private static MemoryOperations memory; //avoid gc static void Main(string[] args) { RPCAbleMethods.Load(); NetPeerConfiguration config = new NetPeerConfiguration("of_masterserver") { Port = PORT, MaximumConnections = (2 ^ 32 - 1), AcceptIncomingConnections = true, }; peer = new NetServer(config); peer.Start(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("> Server started, server version: " + VERSION); Console.ForegroundColor = ConsoleColor.White; memory = new MemoryOperations(); ServerLoop.StartServerLoop(peer); while (ServerLoop.EnabledLooping) { Thread.Sleep(1000); } }
public Server() { dm = new DataManager(); maxPlayers = 4; minPlayers = 2; winningWeight = 10; pelletWeight = 1; numberOfClients = 0; numberOfPellets = 5; loginNames = new List<string>(); availableClientNumbers = new LinkedList<int>(); for (int i = 1; i <= 4; i++) availableClientNumbers.AddLast(i); TopBorderPosition = RightBorderPosition = 5.0f; BottomBorderPosition = LeftBorderPosition = -5.0f; rng = new Random(); listener = new TcpListener(4188); socArray = new Socket[maxPlayers]; clientArray = new LinkedList<Client>(); pelletArray = new Pellet[numberOfPellets]; listenerThead = new Thread(new ThreadStart(this.Listen)); uniClock = new Stopwatch(); commandClock = new Stopwatch(); loop = new ServerLoop(this); loop.loopThread.Start(); }
private void Start() { MaximumPlayers = ServerSettings.maxPlayerCount; playerIdList = Enumerable.Range(1, MaximumPlayers).Select(x => (ushort)x).ToList(); serverLoop = new ServerLoop(playerPrefab); StartServer(); }
private static void Shutdown(NetIncomingMessage message) { string AdminLogin = message.ReadString(); string AdminPassword = message.ReadString(); Console.WriteLine("Shutdown"); try { PlayerInfo request = MemoryOperations.PlayersData.Keys.FirstOrDefault(x => x.Nickname == AdminLogin); if (request.Password == AdminPassword && request.AccessLevel >= 16) { MemoryOperations.RefreshPlayersAccountsInMemory(0); ServerLoop.CloseLooping(); } } catch { Environment.Exit(0); } }
public void OnApplicationIdle(object sender, EventArgs e) { while (this.AppStillIdle) { ServerLoop.Loop(); if (Settings.Sleep > 0) { Thread.Sleep(Settings.Sleep); } } if (!GameRunning) { Application.Exit(); } }
public void Start() { m_serverLoop = this; //服务器socket 协议族 server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //绑定端口号 server.Bind(new IPEndPoint(IPAddress.Any, 10086)); //可以监听的客户端数目 server.Listen(100); //开辟新的线程 处理客户端请求 Thread listenThread = new Thread(ReceiveClient); //开启线程 listenThread.Start(); //后台运行 listenThread.IsBackground = true; List_clients = new List <TcpSocket>(); }