자잘한 수정, 이제 다른 소켓으로 쓰기 요청 할 수 있을 듯
This commit is contained in:
@@ -1,11 +1,81 @@
|
||||
#pragma once
|
||||
#include "Utils/ThreadPool.hpp"
|
||||
#include "Utils/ConfigManager.hpp"
|
||||
#include "Socket/IOCP.hpp"
|
||||
#include "Packet/Packet.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
class ServerManager {
|
||||
public:
|
||||
void init();
|
||||
void
|
||||
void _IOCPClient(ThreadPool* thread, IOCPPASSINDATA* data);
|
||||
|
||||
PacketSet packetParser(Packet Packet);
|
||||
|
||||
template<typename _Callable>
|
||||
void init(_Callable _IOCPClient) {
|
||||
auto config = ConfigManager::load();
|
||||
log::setDefaultLogger(config.logLevel, config.logFileName, config.logfileSize, config.logfileCount);
|
||||
threadPool_.init(0);
|
||||
iocp_.init(&threadPool_, _IOCPClient);
|
||||
|
||||
struct Address serveraddr;
|
||||
if (config.ipVersion == 4) {
|
||||
listenSock_.init(AF_INET);
|
||||
serveraddr.set(AF_INET, INADDR_ANY, config.listenPort);
|
||||
clientAddr_.setType(AF_INET);
|
||||
}
|
||||
else if (config.ipVersion == 6) {
|
||||
listenSock_.init(AF_INET6);
|
||||
serveraddr.set(AF_INET6, in6addr_any, config.listenPort);
|
||||
clientAddr_.setType(AF_INET6);
|
||||
}
|
||||
listenSock_.bind(serveraddr);
|
||||
listenSock_.listen(SOMAXCONN);
|
||||
}
|
||||
|
||||
void init() {
|
||||
init([this](ThreadPool* thread, IOCPPASSINDATA* data) {
|
||||
_IOCPClient(thread, data);
|
||||
});
|
||||
}
|
||||
|
||||
void registerUser(std::string userName, std::shared_ptr<TCPSocket> sock);
|
||||
void deleteUser(Snowflake UID);
|
||||
std::vector<std::pair<Snowflake, std::string>> getUserList();
|
||||
|
||||
void createRoom(std::string roomName);
|
||||
void deleteRoom(Snowflake RID);
|
||||
std::vector<std::pair<Snowflake, std::string>> getRoomList();
|
||||
|
||||
void joinRoom(Snowflake UID, Snowflake RID);
|
||||
void exitRoom(Snowflake UID, Snowflake RID);
|
||||
|
||||
Snowflake generateID();
|
||||
|
||||
void run();
|
||||
private:
|
||||
ThreadPool threadPool_;
|
||||
IOCP iocp_;
|
||||
|
||||
TCPSocket listenSock_;
|
||||
|
||||
TCPSocket clientSock_;
|
||||
struct Address clientAddr_;
|
||||
|
||||
std::mutex resourceMutex_;
|
||||
std::mutex snowflakeGenerateMutex_;
|
||||
|
||||
std::unordered_map<Snowflake, std::string> roomNames_;
|
||||
|
||||
std::unordered_map<Snowflake, std::unordered_map<Snowflake, std::shared_ptr<TCPSocket>>> rooms_;
|
||||
|
||||
std::unordered_map<Snowflake, std::shared_ptr<TCPSocket>> UID2userSocket_;
|
||||
std::unordered_map<TCPSocket*, Snowflake> userSocket2UID_;
|
||||
|
||||
std::unordered_map<Snowflake, std::string> userNames_;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user