private static void GetSearchPlayer(ThreadClient client, string login, bool v) { SQLQuery sQLQuery = new SQLQuery(); dynamic dynamic = sQLQuery.GetSearchPlayer(login, v); client.SendMessage(dynamic); }
private static void NewMessageChatGlobal(ThreadClient client, int sender_id_tbPlayer, string messageMessage, DateTime dateTimeMessage, string loginSender) { SQLQuery sQLQuery = new SQLQuery(); Boolean OkSend = sQLQuery.SqlInsertMenssageGlobal(sender_id_tbPlayer, messageMessage, dateTimeMessage); switch (OkSend) { case true: foreach (ThreadClient threadClient in Login_threadClients) { string sender = loginSender; string message = messageMessage; string date = dateTimeMessage.ToString(); threadClient.SendMessage(new { Type = GET_INFO_GAME_SUCESS, Function = "message", sender, message, date }); } break; case false: client.SendMessage(new { Type = GET_INFO_GAME_ERRO }); break; } }
private static void GetPlayerPosition(ThreadClient client, int idPlayer) { SQLQuery sQLQuery = new SQLQuery(); dynamic dynamic = sQLQuery.GetPlayerPosition(idPlayer); client.SendMessage(dynamic); }
private static void GetProfilePlayer(ThreadClient client, string login, string password) { SQLQuery sQLQuery = new SQLQuery(); dynamic dynamic = sQLQuery.LoginGetPlayer(login, password); client.SendMessage(dynamic); }
public void Client() { String message = ""; try { NetworkStream = TcpClient.GetStream(); StreamReader = new StreamReader(NetworkStream); StreamWriter = new StreamWriter(NetworkStream); int i; bool quit = false; while (!quit) { } } catch (IOException ioe) { } finally { TcpClient.Close(); // Shutdown and end connection ThreadClient.IsBackground = true; ThreadClient.Abort(); } }
private static void SetRoomPlayer(ThreadClient client, string loginPlayer, int typeRoom, int betRoom, bool waiting) { switch (waiting) { case true: if (Rooms[typeRoom] == null) { Rooms[typeRoom] = new Dictionary <string, ThreadClient>(); } Console.WriteLine($"Client Enter Room {typeRoom}"); if (Rooms[typeRoom].ContainsKey(loginPlayer) == false) { Rooms[typeRoom].Add(loginPlayer, client); if (Rooms[typeRoom].Count() < 2) { client.SendMessage(new { Type = BATTLE_TYPE_ENTERED_BATTLE_SUCCESS }); } if (Rooms[typeRoom].Count() == 2) { CreateBattle(typeRoom, betRoom); } } break; case false: Console.WriteLine($"Client Exit Room { typeRoom}"); if (Rooms[typeRoom].ContainsKey(loginPlayer) == true) { Rooms[typeRoom].Remove(loginPlayer); } break; } }
private static void SyncLocalIndian(int newLocal, int oldLocal, string loginPlayer) { if (BattlePlayers.ContainsKey(loginPlayer)) { ThreadClient thread = BattlePlayers[loginPlayer]; thread.SendMessage(new { Type = BATTLE_TYPE_SYNC_LOCAL_INDIAN_SUCCESS, oldLocal, newLocal }); } }
private static void GetRankig(ThreadClient client) { SQLQuery sQLQuery = new SQLQuery(); List <dynamic> dynamics = sQLQuery.SqlGetRanking(); foreach (dynamic din in dynamics) { client.SendMessage(din); } }
private static void GetItemArsenal(ThreadClient client, int idPlayer) { SQLQuery sQLQuery = new SQLQuery(); List <dynamic> dynamics = sQLQuery.SqlGetItemArsenal(idPlayer); foreach (dynamic din in dynamics) { client.SendMessage(din); } }
private static void GetMessageChat(ThreadClient client, int sender, int receiver) { SQLQuery sQLQuery = new SQLQuery(); List <dynamic> dynamics = sQLQuery.SqlGetMessage(sender, receiver); foreach (dynamic din in dynamics) { client.SendMessage(din); } }
private static void DestroyedButton(int[] locals, string loginPlayerEnemy, int typeItem) { ThreadClient clientee = BattlePlayers[loginPlayerEnemy]; clientee.SendMessage(new { Type = BATTLE_TYPE_SET_DESTROYED_SIDE_SUCECSS, locals, typeItem }); }
private static void NewMessagechatBattle(ThreadClient client, string messageMessage, string login, string loginPlayerEnemy) { if (BattlePlayers.ContainsKey(login)) { ThreadClient thread = BattlePlayers[loginPlayerEnemy]; thread.SendMessage(new { Type = NEW_MESSAGE_CHAT_BATTLE_SUCESS, messageMessage = $"{login}: {messageMessage}" }); } else { client.SendMessage(new { Type = NEW_MESSAGE_CHAT_BATTLE_ERRO }); } }
static void OnClientConnect(object sender, EventArgs eventArgs) { ConnectEventArgs connectEventArgs = eventArgs as ConnectEventArgs; if (connectEventArgs != null) { ThreadClient client = connectEventArgs.Client; clients.Add(client); Console.WriteLine($"Cliente nº {clients.Count()} conectou-se."); } }
private static void OnClientConnect(object sender, EventArgs e) { ConnectEventArgs connectEventArgs = e as ConnectEventArgs; if (connectEventArgs != null) { ThreadClient client = connectEventArgs.Client; Login_threadClients.Add(client); Console.WriteLine("Client conected"); } }
private static void InsertBuyItem(List <dynamic> DinBuy, ThreadClient client, Int32 idPlayer, Int32 listSize, int emerald) { if (DinBuy.Count == listSize) { bool InsertSucess = false; Int32 id_tbItem = 0; Int32 amountItemPurchase = 0; Int32 valueUnitItemPurchase = 0; Int32 valueTotalItemPurchase = 0; DateTime dateTime = DateTime.Now; SQLQuery sQLQuery = new SQLQuery(); Int32? idPuchese = sQLQuery.SqlSetPurchase(dateTime, idPlayer); if (idPuchese != null) { foreach (dynamic dynBuy in BuyList) { id_tbItem = dynBuy.id_tbItem; amountItemPurchase = dynBuy.amountItemPurchase; valueUnitItemPurchase = dynBuy.valueUnitItemPurchase; valueTotalItemPurchase = dynBuy.valueTotalItemPurchase; InsertSucess = sQLQuery.SqlSetItemPuchase((Int32)idPuchese, id_tbItem, amountItemPurchase, valueUnitItemPurchase, valueTotalItemPurchase); if (InsertSucess == false) { break; } } switch (InsertSucess) { case true: UpdateArsenal(client, idPlayer, DinBuy, emerald); break; case false: BuyPlayers.Remove(idPlayer); client.SendMessage(new { Type = STORE_TYPE_SET_BUY_ERRO }); break; } } else { BuyPlayers.Remove(idPlayer); client.SendMessage(new { Type = STORE_TYPE_SET_BUY_ERRO }); } } else { client.SendMessage(new { Type = PROGRESSBAR_TYPE_NEXT }); } }
private static void SetOffOrOnPlayer(ThreadClient client, int idPlayer, int OffOn) { SQLQuery sQLQuery = new SQLQuery(); Boolean OK = sQLQuery.SqlSetOffOnLine(idPlayer, OffOn); switch (OK) { case true: Console.WriteLine("Status Gravado"); switch (OffOn) { case 1: Console.WriteLine("Client ONLINE"); if (MessegeOnLine.ContainsKey(idPlayer) == false) { MessegeOnLine.Add(idPlayer, client); client.SendMessage(new { Type = MESSAGE_TYPE_SET_PLAYER_ON_LINE_SUCCESS }); } else { MessegeOnLine.Remove(idPlayer); MessegeOnLine.Add(idPlayer, client); client.SendMessage(new { Type = MESSAGE_TYPE_SET_PLAYER_ON_LINE_SUCCESS }); } break; case 0: Console.WriteLine("Client OFFLINE"); if (MessegeOnLine.ContainsKey(idPlayer) == true) { MessegeOnLine.Remove(idPlayer); } break; } break; case false: Console.WriteLine("status não gravado."); client.SendMessage(new { Type = MESSAGE_TYPE_SET_PLAYER_ON_LINE_ERRO }); break; } UpdateStatus(idPlayer); }
private static void UpdateStatus(int idPlayer) { int id = 0; ThreadClient client = null; foreach (var clients in MessegeOnLine) { id = (int)clients.Key; client = (ThreadClient)clients.Value; if (idPlayer != id) { GetListContacts(client, id); } } }
private static void SetNewMessage(ThreadClient client, int sender_id_tbPlayer, int receiver_id_tbPlayer, string messageMessage, DateTime dateTimeMessage, string loginSender) { SQLQuery sQLQuery = new SQLQuery(); Boolean OkSend = sQLQuery.SqlInsertMenssage(sender_id_tbPlayer, receiver_id_tbPlayer, messageMessage, dateTimeMessage); Boolean OK = MessegeOnLine.ContainsKey(receiver_id_tbPlayer); switch (OkSend) { case true: switch (OK) { case true: ThreadClient receiver = MessegeOnLine[receiver_id_tbPlayer]; string format = "yyyy/MM/dd HH:mm:ss"; string date = dateTimeMessage.ToString(format); receiver.SendMessage(new { Type = MESSAGE_TYPE_NEW_MESSAGE_ONLINE, loginSender, sender_id_tbPlayer, messageMessage, date }); break; case false: client.SendMessage(new { Type = MESSAGE_TYPE_SEVER, message = "Server: Client está Offline, sua mensagem foi gravada", }); break; } break; case false: client.SendMessage(new { Type = MESSAGE_TYPE_SEVER, message = "Server Log: Erro ao gravar mensagem no banco de dados", }); break; } }
//[Test] public void MainServiceListenerAndClient() { ThreadClient client = new ThreadClient(); ThreadListener listener = new ThreadListener(); // start the listener & wait until it has started (new Thread(new ThreadStart(listener.Run))).Start(); commonLock.WaitUntilEq(LISTENER_STARTED, 4000); // start the client (new Thread(new ThreadStart(client.Run))).Start(); commonLock.WaitUntilEq(CLIENT_STARTED, 4000); Console.WriteLine("am i coming here?"); if (client.HasErrors() || listener.HasErrors()) { Assert.Fail(); } }
private static void SetNewPlayer(ThreadClient client, string fullNamePlayer, string loginPlayer, string passwordPlayer, string secretPhresePlayer, string avatarPlayer) { SQLQuery sQLQuery = new SQLQuery(); Boolean OK = sQLQuery.SqlSetNewPlayer(fullNamePlayer, loginPlayer, passwordPlayer, secretPhresePlayer, avatarPlayer); switch (OK) { case true: client.SendMessage(new { Type = REGISTER_TYPE_RETURN_SUCCESS }); break; case false: client.SendMessage(new { Type = REGISTER_TYPE_RETURN_ERROR }); break; } }
private static void UpdatePlayer(ThreadClient client, string loginPlayer, string passwordPlayer, string secretPhresePlayer) { SQLQuery sQLQuery = new SQLQuery(); Boolean OK = sQLQuery.SqlUpdatePassword(loginPlayer, passwordPlayer, secretPhresePlayer); switch (OK) { case true: client.SendMessage(new { Type = FORGOT_PASSWORD_TYPE_RETURN_SUCCESS }); break; case false: client.SendMessage(new { Type = FORGOT_PASSWORD_TYPE_RETURN_ERROR }); break; } }
public void Client() { try { NetworkStream = TcpClient.GetStream(); StreamReader = new StreamReader(NetworkStream); StreamWriter = new StreamWriter(NetworkStream); while (!quit) { ; } } catch (IOException ioe) { Console.WriteLine(ioe); } finally { TcpClient.Close(); // Shutdown and end connection ThreadClient.IsBackground = true; ThreadClient.Abort(); } }
private static void UpdateArsenal(ThreadClient client, int idPlayer, List <dynamic> DinBuy, int emerald) { Console.WriteLine("ARSENAL_TYPE_GET_ITEM"); Boolean InsertSucess = false; Int32 id_tbItem = 0; Int32 amountItemPurchase = 0; SQLQuery sQLQuery = new SQLQuery(); foreach (dynamic dynBuy in BuyList) { id_tbItem = dynBuy.id_tbItem; amountItemPurchase = dynBuy.amountItemPurchase; InsertSucess = sQLQuery.SqlSetOrUpdateArsenal(idPlayer, id_tbItem, amountItemPurchase); if (InsertSucess == false) { break; } } if (InsertSucess == true) { BuyPlayers.Remove(idPlayer); if (SetEmeraldUpdatePlayer(client, idPlayer, emerald) == true) { GetItemArsenal(client, idPlayer); client.SendMessage(new { Type = STORE_TYPE_SET_BUY_SUCCESS }); } else { client.SendMessage(new { Type = ARSENAL_TYPE_GET_ITEM_ERRO }); } } else { client.SendMessage(new { Type = ARSENAL_TYPE_GET_ITEM_ERRO }); } }
private static void OnClientReceiveMessage(object sender, EventArgs e) // { MessageEventArgs messageEventArgs = e as MessageEventArgs; ThreadClient client = sender as ThreadClient; string fullNamePlayer, loginPlayer, passwordPlayer, secretPhresePlayer, avatarPlayer, messageMessage; int sender_id_tbPlayer, receiver_id_tbPlayer, idPlayer, id_tbItem, amountItemPurchase, valueUnitItemPurchase, valueTotalItemPurchase, listSize, emerald; if (messageEventArgs != null) { switch (messageEventArgs.Message.GetInt32("Type")) { case LOGIN_TYPE_GET_PLAYER: Console.WriteLine("LOGIN_TYPE_GET_PLAYER"); string login = messageEventArgs.Message.GetString("loginPlayer"); string password = messageEventArgs.Message.GetString("passwordPlayer"); GetProfilePlayer(client, login, password); break; case REGISTER_TYPE_SET_NEW_PLAYER: Console.WriteLine("REGISTER_TYPE_SET_NEW_PLAYER"); fullNamePlayer = messageEventArgs.Message.GetString("fullNamePlayer"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); passwordPlayer = messageEventArgs.Message.GetString("passwordPlayer"); secretPhresePlayer = messageEventArgs.Message.GetString("secretPhresePlayer"); avatarPlayer = messageEventArgs.Message.GetString("avatarPlayer"); SetNewPlayer(client, fullNamePlayer, loginPlayer, passwordPlayer, secretPhresePlayer, avatarPlayer); break; case FORGOT_PASSWORD_TYPE_SET_NEW_PASSWORD: Console.WriteLine("FORGOT_PASSWORD_TYPE_SET_NEW_PASSWORD"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); passwordPlayer = messageEventArgs.Message.GetString("passwordPlayer"); secretPhresePlayer = messageEventArgs.Message.GetString("secretPhresePlayer"); UpdatePlayer(client, loginPlayer, passwordPlayer, secretPhresePlayer); break; case MESSAGE_TYPE_SEND_NEW_MESSAGE: Console.WriteLine("MESSAGE_TYPE_SEND_NEW_MESSAGE"); sender_id_tbPlayer = messageEventArgs.Message.GetInt32("sender_id_tbPlayer"); receiver_id_tbPlayer = messageEventArgs.Message.GetInt32("receiver_id_tbPlayer"); messageMessage = messageEventArgs.Message.GetString("messageMessage"); loginPlayer = messageEventArgs.Message.GetString("name_Sender"); DateTime dateTime = DateTime.Now; SetNewMessage(client, sender_id_tbPlayer, receiver_id_tbPlayer, messageMessage, dateTime, loginPlayer); break; case MESSAGE_TYPE_SET_PLAYER_ON_LINE: Console.WriteLine("MESSAGE_TYPE_SET_PLAYER_ON_LINE"); idPlayer = messageEventArgs.Message.GetInt32("idPlayer"); SetOffOrOnPlayer(client, idPlayer, 1); break; case MESSAGE_TYPE_SET_PLAYER_OFF_LINE: Console.WriteLine("MESSAGE_TYPE_SET_PLAYER_OFF_LINE"); idPlayer = messageEventArgs.Message.GetInt32("idPlayer"); SetOffOrOnPlayer(client, idPlayer, 0); break; case MESSAGE_TYPE_GET_CONTACTS: Console.WriteLine("MESSAGE_TYPE_GET_CONTACTS"); idPlayer = messageEventArgs.Message.GetInt32("idPlayer"); GetListContacts(client, idPlayer); break; case MESSAGE_TYPE_GET_MESSAGES: Console.WriteLine("MESSAGE_TYPE_GET_MESSAGES"); sender_id_tbPlayer = messageEventArgs.Message.GetInt32("idSender"); receiver_id_tbPlayer = messageEventArgs.Message.GetInt32("idReceiver"); GetMessageChat(client, sender_id_tbPlayer, receiver_id_tbPlayer); break; case MESSAGE_TYPE_GET_SEARCH_PLAYER: Console.WriteLine("MESSAGE_TYPE_GET_SEARCH_PLAYER"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); GetSearchPlayer(client, loginPlayer, false); break; case MESSAGE_TYPE_GET_MESSAGE_BOX: Console.WriteLine("MESSAGE_TYPE_GET_MESSAGE_BOX"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); GetSearchPlayer(client, loginPlayer, false); break; case STORE_TYPE_GET_ITEM: Console.WriteLine("STORE_TYPE_GET_ITEM"); GetItemStore(client); break; case ARSENAL_TYPE_GET_ITEM: Console.WriteLine("ARSENAL_TYPE_GET_ITEM"); idPlayer = messageEventArgs.Message.GetInt32("idPlayer"); GetItemArsenal(client, idPlayer); break; case STORE_TYPE_SET_BUY: Console.WriteLine("STORE_TYPE_SET_BUY"); idPlayer = messageEventArgs.Message.GetInt32("idPlayer"); id_tbItem = messageEventArgs.Message.GetInt32("id_tbItem"); amountItemPurchase = messageEventArgs.Message.GetInt32("amountItemPurchase"); valueUnitItemPurchase = messageEventArgs.Message.GetInt32("valueUnitItemPurchase"); valueTotalItemPurchase = messageEventArgs.Message.GetInt32("valueTotalItemPurchase"); emerald = messageEventArgs.Message.GetInt32("ValueWallet"); listSize = messageEventArgs.Message.GetInt32("listSize"); SetItemPurchase(client, idPlayer, id_tbItem, amountItemPurchase, valueUnitItemPurchase, valueTotalItemPurchase, listSize, emerald); break; case PLAYER_TYPE_GET_POSITION: Console.WriteLine("PLAYER_TYPE_GET_POSITION"); idPlayer = messageEventArgs.Message.GetInt32("idPlayer"); GetPlayerPosition(client, idPlayer); break; case BATTLE_TYPE_ENTERED_BATTLE: Console.WriteLine("BATTLE_TYPE_ENTERED_BATTLE"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); int typeRoom = messageEventArgs.Message.GetInt32("typeBattle"); int betRoom = messageEventArgs.Message.GetInt32("betRoom"); SetRoomPlayer(client, loginPlayer, typeRoom, betRoom, true); break; case BATTLE_TYPE_EXIT_BATTLE: Console.WriteLine("BATTLE_TYPE_EXIT_BATTLE"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); typeRoom = messageEventArgs.Message.GetInt32("typeBattle"); betRoom = messageEventArgs.Message.GetInt32("betRoom"); SetRoomPlayer(client, loginPlayer, typeRoom, betRoom, false); break; case BATTLE_TYPE_SET_DESTROYED_SIDE: int[] locals = messageEventArgs.Message.GetSingleDimArrayInt32("locals"); string loginPlayerEnemy = messageEventArgs.Message.GetString("loginPlayer"); int typeItem = messageEventArgs.Message.GetInt32("typeItem"); DestroyedButton(locals, loginPlayerEnemy, typeItem); break; case BATTLE_TYPE_SYNC_LOCAL_INDIAN: int newLocal = messageEventArgs.Message.GetInt32("newLocal"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); int oldLocal = messageEventArgs.Message.GetInt32("oldLocal"); SyncLocalIndian(newLocal, oldLocal, loginPlayer); break; case NEW_MESSAGE_CHAT_BATTLE: Console.WriteLine("NEW_MESSAGE_CHAT_BATTLE"); messageMessage = messageEventArgs.Message.GetString("messageMessage"); loginPlayer = messageEventArgs.Message.GetString("loginPlayer"); loginPlayerEnemy = messageEventArgs.Message.GetString("loginPlayerEnemy"); NewMessagechatBattle(client, messageMessage, loginPlayer, loginPlayerEnemy); break; case GET_INFO_GAME: string Function = messageEventArgs.Message.GetString("Function"); Console.WriteLine($"GET_INFO_GAME: { Function }"); if (Function == "message") { GetMessageGLobal(client); } else if (Function == "ranking") { GetRankig(client); } else { GetMessageGLobal(client); GetRankig(client); } break; case SET_MESSAGE_GLOBAL: { sender_id_tbPlayer = messageEventArgs.Message.GetInt32("sender_id_tbPlayer"); messageMessage = messageEventArgs.Message.GetString("messageMessage"); loginPlayer = messageEventArgs.Message.GetString("name_Sender"); DateTime dateT = DateTime.Now; NewMessageChatGlobal(client, sender_id_tbPlayer, messageMessage, dateT, loginPlayer); } break; } } }
static void OnClientReceiveMessage(object sender, EventArgs eventArgs) { MessageEventArgs messageEventArgs = eventArgs as MessageEventArgs; if (messageEventArgs != null) { Message message = messageEventArgs.Message; int type = message.GetInt32("type"); ThreadClient client = sender as ThreadClient; switch (type) { case MESSAGE_TYPE_GET_MESSAGES: if (client != null) { List <dynamic> messages = GetMessages(); foreach (dynamic messageFromDB in messages) { client.SendMessage(messageFromDB); } } break; case MESSAGE_TYPE_SEND_NEW_MESSAGE: int userIdNewMsg = message.GetInt32("userId"); string userName = message.GetString("userName"); string namePlayer = message.GetString("namePlayer"); string dateTime = message.GetString("dateTime"); string messageText = message.GetString("messageText"); if (InsertMessage(userIdNewMsg, messageText) == true) { foreach (ThreadClient clientNewMsg in clients) { clientNewMsg.SendMessage(new { type = MESSAGE_TYPE_READ_NEW_MESSAGE, userName, namePlayer, dateTime, messageText }); } } break; case MESSAGE_TYPE_INSERT_USER_REQUEST: if (client != null) { string name = message.GetString("name"); string username = message.GetString("username"); string password = message.GetString("password"); string birthDate = message.GetString("birthDate"); string securityText = message.GetString("securityText"); bool userInserted = InsertUser(name, username, password, birthDate, securityText); if (userInserted == true) { client.SendMessage(new { type = MESSAGE_TYPE_INSERT_USER_SUCCESS, success = "Usuário cadastrado com sucesso" }); } else { if (uniqueUser == false) { client.SendMessage(new { type = MESSAGE_TYPE_INSERT_USER_ERROR, error = $"Já existe um usuário '{username}' cadastrado no sistema" }); } else { client.SendMessage(new { type = MESSAGE_TYPE_INSERT_USER_ERROR, error = "Falha ao tentar cadastrar o usuário, favor tentar novamente" }); } } } break; case MESSAGE_TYPE_GET_USER_REQUEST: if (client != null) { string login = message.GetString("login"); string password = message.GetString("password"); dynamic userData = null; bool hasException = false; try { userData = GetUser(login, password); } catch { hasException = true; } if (hasException) { client.SendMessage(new { type = MESSAGE_TYPE_GET_USER_ERROR, error = "Falha ao tentar fazer o login, favor tentar novamente" }); } else { if (userData != null) { client.SendMessage(userData); } else { client.SendMessage(new { type = MESSAGE_TYPE_GET_USER_ERROR, error = "Falha ao tentar fazer o login, usuário ou senha inválido" }); } } } break; case MESSAGE_TYPE_RECOVERY_USER_PASSWORD_REQUEST: if (client != null) { string username = message.GetString("username"); string birthDate = message.GetString("birthDate"); string securityText = message.GetString("securityText"); dynamic recoveryData = null; bool hasException = false; try { recoveryData = GetValidateUser(username, birthDate, securityText); } catch { hasException = true; } if (hasException) { client.SendMessage(new { type = MESSAGE_TYPE_RECOVERY_USER_PASSWORD_ERROR, error = "Falha ao recuperar dados, favor tentar novamente" }); } else { if (recoveryData != null) { client.SendMessage(recoveryData); } else { client.SendMessage(new { type = MESSAGE_TYPE_RECOVERY_USER_PASSWORD_ERROR, error = "Falha ao recuperar dados, favor tentar novamente" }); } } } break; case MESSAGE_TYPE_UPDATE_PASSWORD_REQUEST: if (client != null) { int idPlayer = message.GetInt32("idPlayer"); string password = message.GetString("password"); bool updateResult = false; bool hasException = false; try { updateResult = UpdatePassword(idPlayer, password); } catch { hasException = true; } if (hasException) { client.SendMessage(new { type = MESSAGE_TYPE_UPDATE_PASSWORD_ERROR, error = "Falha ao recuperar dados, favor tentar novamente" }); } else { if (updateResult == true) { client.SendMessage(new { type = MESSAGE_TYPE_UPDATE_PASSWORD_SUCCESS }); } else { client.SendMessage(new { type = MESSAGE_TYPE_UPDATE_PASSWORD_ERROR, error = "Falha ao recuperar dados, favor tentar novamente" }); } } } break; case MESSAGE_TYPE_MATCH_DATA_REQUEST: totPlayersInMatch++; if (totPlayersInMatch == 2) { totPlayersInMatch = 0; StartMatch(); } else { client.SendMessage(new { type = MESSAGE_TYPE_MATCH_DATA_WAITING }); } break; case MESSAGE_TYPE_MATCH_ENEMY_ATTACK: if (client != null) { foreach (ThreadClient threadClient in clients) { if (threadClient.GetNumber() != client.GetNumber()) { threadClient.SendMessage(new { type = MESSAGE_TYPE_MATCH_ENEMY_ATTACK, line = message.GetInt32("line"), column = message.GetInt32("column") }); } } } break; case MESSAGE_TYPE_MATCH_END_GAME: int isWinner = 0, expPlayer1 = 0, expPlayer2 = 0; char sitPlayer1 = 'N', sitPlayer2 = 'N'; if (client != null) { foreach (ThreadClient threadClient in clients) { if (message.GetInt32("myUnities") != 0) { isWinner = 1; } threadClient.SendMessage(new { type = MESSAGE_TYPE_MATCH_END_GAME, myUnities = message.GetInt32("myUnities"), enemyUnities = message.GetInt32("enemyUnities"), isWinner = isWinner }); } if (isWinner == 1) { sitPlayer1 = 'S'; expPlayer1 = 100; expPlayer2 = 20; } else { sitPlayer2 = 'S'; expPlayer1 = 20; expPlayer2 = 100; } EndMatch(1, 2, "0", sitPlayer1, sitPlayer2, expPlayer1, expPlayer2); } break; } } }
private static Boolean SetEmeraldUpdatePlayer(ThreadClient client, int idPlayer, int emerald) { SQLQuery sQLQuery = new SQLQuery(); return(sQLQuery.SqlUpdateEmaraldPlayer(idPlayer, emerald)); }
/// <summary> /// Listens for messages from a client /// </summary> public void ClientThread() { string msg = ""; try { NetworkStream = Client.GetStream(); StreamReader = new StreamReader(NetworkStream); StreamWriter = new StreamWriter(NetworkStream); ContestInfo info = contestPresenter.CurrentContest.Info; msg = "contest:" + info.Name + "|" + info.City + "|" + info.Arena; // contest: Example Event|Lyon|Arena StreamWriter.WriteLine(msg); StreamWriter.Flush(); while (true) { // read what the client has to say msg = StreamReader.ReadLine(); if (msg == null || msg.StartsWith("quit")) { break; } else if (msg.StartsWith("Login:"******"denied"); StreamWriter.Flush(); } } else if (msg.StartsWith("Points:")) { Points = msg.Substring(7); AddPointToList(Points.ToString()); } } } catch (IOException ioe) { Console.WriteLine(ioe.Message); } finally { if (!IsHost) { Client.Close(); foreach (var client in Server.ClientList) { if (this == client) { Server.ClientList.Remove(client); break; } } Server.UpdateJudgeListView(); ThreadClient.Abort(); } } }