private static void ClientSendChatMessageRequest(Socket clientSocket, List <string> content) { // [codigo, idpartida, usuario, mensaje] var playersData = PartidaNetwork.GetPlayersData(int.Parse(content[1])); var chatMessagePackage = CreatePackage(new List <Dictionary <string, object> >() { { new Dictionary <string, object>() { { "code", (byte)NetworkServerResponses.ChatMessage }, { "username", content[2] }, { "message", content[3] } } } }); playersData.RemoveAll(x => x.ContainsKey("code")); foreach (var playerData in playersData) { if (clients.ContainsValue((int)playerData["idcuenta"])) { Send(clients.FirstOrDefault(x => x.Value == (int)playerData["idcuenta"]).Key, chatMessagePackage); } } }
public static bool LeaveGame(int idcuenta, int idpartida) { var players = PartidaNetwork.GetPlayersData(idpartida); players.RemoveAll(x => x.ContainsKey("code")); var player = players.Find(x => (int)x["idcuenta"] == idcuenta); if (player == null) { return(false); } return(Database.ExecuteUpdate( "IF EXISTS (SELECT idjugador FROM jugador WHERE idjugador = @idjugador AND idpartida = @idpartida AND anfitrion = 1) " + "BEGIN " + "DELETE FROM jugador WHERE idjugador = @idjugador AND idpartida = @idpartida; " + "IF NOT EXISTS (SELECT TOP(1) idjugador FROM jugador WHERE idpartida = @idpartida) " + "BEGIN " + "DELETE FROM partida WHERE idpartida = @idpartida; " + "END " + "ELSE " + "BEGIN " + "UPDATE TOP(1) jugador SET anfitrion = 1 WHERE idpartida = @idpartida; " + "END " + "END " + "ELSE IF EXISTS (SELECT idjugador FROM jugador WHERE idjugador = @idjugador AND idpartida = @idpartida) " + "BEGIN " + "DELETE FROM jugador WHERE idjugador = @idjugador AND idpartida = @idpartida; " + "IF NOT EXISTS (SELECT TOP(1) idjugador FROM jugador WHERE idpartida = @idpartida) " + "BEGIN " + "DELETE FROM partida WHERE idpartida = @idpartida; " + "END " + "END", new Dictionary <string, object>() { { "@idjugador", (int)player["idjugador"] }, { "@idpartida", idpartida } } )); }
private static void ClientGetGamePlayers(Socket clientSocket, List <string> content) { var playersDataPackage = CreatePackage(PartidaNetwork.GetPlayersData(int.Parse(content[1]))); Send(clientSocket, playersDataPackage); }
private static void ClientGetGamesRequest(Socket clientSocket) { var gamesDataPackage = CreatePackage(PartidaNetwork.GetGames()); Send(clientSocket, gamesDataPackage); }