/// <summary> /// Thread that accepts clients /// </summary> void AcceptClients() { try { while (true) { var newSocket = Socket.AcceptTcpClient(); var newClient = new ServerClient(newSocket); newClient.zId = GetNextId(); newClient.zNetidBytes = BitConverter.GetBytes(newClient.zId); newClient.Hero.Netid = newClient.Id; newClient.ReceiveThread.Start(); //by default, everyone starts in lorencia, relocation occurs when client sends ready //message with correct room id ClientMutex.WaitOne(); Rooms[MobMap.Lorencia].Clients.Add(newClient); ClientMutex.ReleaseMutex(); newClient.Room = Rooms[MobMap.Lorencia]; //send welcome msg newClient.SendMessage(MsgHeader.Welcome); } } catch (SocketException se) { if (se.ErrorCode == 10004 && State == ServerState.Stopped) { } else { throw se; } } }
/// <summary> /// Thread that accepts clients /// </summary> void AcceptClients() { try { while (true) { var newSocket = Socket.AcceptTcpClient(); var newClient = new ServerClient(newSocket); newClient.zId = GetNextId(); newClient.zNetidBytes = BitConverter.GetBytes(newClient.zId); newClient.Hero.Netid = newClient.Id; newClient.ReceiveThread.Start(); //by default, everyone starts in lorencia, relocation occurs when client sends ready //message with correct room id ClientMutex.WaitOne(); Rooms[MobMap.Lorencia].Clients.Add(newClient); ClientMutex.ReleaseMutex(); newClient.Room = Rooms[MobMap.Lorencia]; //send welcome msg newClient.SendMessage(MsgHeader.Welcome); } } catch (SocketException se) { if (se.ErrorCode == 10004 && State == ServerState.Stopped) { } else throw se; } }