const string send = "/SEND"; //send test public GameServer() { IniFile configServerFile = new IniFile("Config.ini"); Program.userIP = configServerFile.GetValue("USER_CONNECTION", "userIP", "127.0.0.1"); Program.userPort = Program.port = configServerFile.GetInteger("USER_CONNECTION", "port", 3001); Program.maxNumberOfConnections = configServerFile.GetInteger("USER_CONNECTION", "maxNumberOfConnections", 1000); Program.bufferSize = configServerFile.GetInteger("USER_CONNECTION", "bufferSize", 100); Program.backlog = configServerFile.GetInteger("USER_CONNECTION", "backlog", 100); Program.useTempBlackList = configServerFile.GetBoolean("RESTRICTION", "tempBlackList", true); int port = configServerFile.GetInteger("LOGIN_SERVER", "port", 4422); int maxNumberOfConnections = configServerFile.GetInteger("LOGIN_SERVER", "maxNumberOfConnections", 1); int bufferSize = configServerFile.GetInteger("LOGIN_SERVER", "bufferSize", 1024); int backlog = configServerFile.GetInteger("LOGIN_SERVER", "backlog", 1); string key = configServerFile.GetValue("LOGIN_SERVER", "key"); if (key.Length > 0) { loginKey = Encoding.ASCII.GetBytes(key); } IPEndPoint userLocalEndPoint = new IPEndPoint(IPAddress.Any, Program.port); IPEndPoint loginLocalEndPoint = new IPEndPoint(IPAddress.Any, port); userSocketSettings = new SocketListenerSettings(Program.maxNumberOfConnections, Program.backlog, Program.receivePrefixLength, Program.bufferSize, Program.sendPrefixLength, userLocalEndPoint); loginSocketSettings = new SocketListenerSettings(maxNumberOfConnections, backlog, Program.receivePrefixLength, bufferSize, Program.sendPrefixLength, loginLocalEndPoint); Output.WriteLine(ConsoleColor.Green, "GameServer config. Port: " + Program.port.ToString() + " Max connections: " + Program.maxNumberOfConnections.ToString() + " Buffer size: " + Program.bufferSize.ToString()); loginListener = new LoginConnectionListener(Program.bufferSize, loginSocketSettings); userListener = new UserConnectionListener(userSocketSettings); world = new World("maps//map_200x200"); mainServerLoop = new GameServerMainLoop(); }
public UserConnectionListener(SocketListenerSettings theSocketListenerSettings) { this.socketListenerSettings = theSocketListenerSettings; //buffer for all connections, double the number of connections cuz recv and send use own buffer block recvSendBufMenager = new BufferMenager(socketListenerSettings.MaxConnections * 2, socketListenerSettings.BufferSize); // Create connections count enforcer theMaxConnectionsEnforcer = new Semaphore(socketListenerSettings.MaxConnections, socketListenerSettings.MaxConnections); //pool of connections with set of max active connections inactiveConPool = new ConnectionsPool(socketListenerSettings.MaxConnections); activeConPool = new ConcurrentDictionary <int, Connection>(); activeConnectionCount = 0; }
public LoginConnectionListener(int bufsize, SocketListenerSettings theSocketListenerSettings) { bufBlockSize = bufsize; this.socketListenerSettings = theSocketListenerSettings; }