public static void SaveGame() { Cnsl.Log("Saving game", true); try { _gameService.SaveGame(_userService.ActiveUsers.ToList()); Cnsl.Finalize("Saving game"); } catch { Cnsl.Finalize("Saving game", false); } }
public void CloseSocket(int index) { Cnsl.Log("Connection from " + ip + " has been terminated"); var player = Program._userService.ActiveUsers.Find(p => p.Id == Globals.PlayerIDs[index]); if (player != null) { ServerTcp.SendMessage(-1, player.Name + @" has disconnected.", (int)ChatPackets.Notification); player.inGame = false; player.receiving = false; } Program._gameService.SaveGame(new List <User> { player }); socket.Close(); socket = null; Globals.PlayerIDs[index] = null; Program._userService.ActiveUsers.Remove(player); }
private static void PACKET_LOGIN(int connectionId, byte[] data) { var buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadLong(); var user = buffer.ReadString(); var pass = buffer.ReadString(); var validate = Program._userService.PasswordOK(user, pass); if (!validate) { ServerTcp.SendSystemByte(connectionId, SystemBytes.SysInvPass); return; } buffer.Dispose(); var player = Program._userService.LoadPlayer(user); player.inGame = true; player.connectionID = connectionId; Globals.PlayerIDs.Add(connectionId, player.Id); Program._userService.ActiveUsers.Add(player); ServerTcp.SendGlobals(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendItems(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendToGalaxy(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendIngame(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendInventory(connectionId); //ServerTCP.SendNebulae(connectionID); ServerTcp.SendMessage(-1, player.Name + " has connected.", (int)ChatPackets.Notification); System.Threading.Thread.Sleep(250); ServerTcp.SendGalaxy(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendRecipes(connectionId); Globals.FullData = true; Cnsl.Log(user + @" logged in successfully."); player.receiving = true; }
private static void OnClientConnect(IAsyncResult result) { var client = serverSocket.EndAcceptTcpClient(result); serverSocket.BeginAcceptTcpClient(OnClientConnect, null); var port = ((IPEndPoint)client.Client.RemoteEndPoint).Port; if (!Client.ContainsKey(port)) { var newClient = new Clients { socket = client, connectionID = port, ip = client.Client.RemoteEndPoint.ToString() }; Client.Add(port, newClient); Client[port].Start(); Cnsl.Log("Connection received from " + Client[port].ip); return; } }