/// <summary> /// Dispatched version of join game success which can launch the new window /// </summary> /// <param name="game"></param> public void joinGameSuccessDispatched(Game game) { ChatViewModel gameChat = new ChatViewModel(game.id, this, game); gameChat.leaveGame += mgr.leaveGame; gameChat.sendGameChat = sendGameChat; gameChat.leaveGame += exitGame; //Weird error here ChatWindows.Add(gameChat); gameChat.addBuddyList += addToBuddyList; gameChat.wind.sendPM += sendPM; //Create a new GUIBundle and update the game chat window with existing players GUIBundle newGameBund = new GUIBundle(); newGameBund.gameNum = game.id; newGameBund.Users = game.users; updateWindow(newGameBund); currGame = game; }
/// <summary> /// Exits the current game as assigned in the controller /// and closes window /// </summary> public void exitGame() { if (currGame == null) return; exitGame(currGame.id); var winds = from windows in ChatWindows where windows.gameNumber == currGame.id select windows; foreach (var wind in winds) { wind.closeWindow(); } lock (ChatWindows) { ChatWindows.RemoveAll((chatWind) => chatWind.gameNumber == currGame.id); } currGame = null; }
/// <summary> /// Messages the KailleraManager to join the selected game /// </summary> /// <param name="game"></param> public void joinSelectedGame(Game game) { if (game == null) return; currGame = game; mgr.tryJoinGame(game); }
//Launch new game chat window public void joinGameSuccess(Game game) { System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => joinGameSuccessDispatched(game))); }
/// <summary> /// Sends the join game message /// </summary> /// <param name="game"></param> public void tryJoinGame(Game game) { messager.AddMessages(new JoinGame(game.id)); tempCurrGame = game; messager.SendMessages(client); }
/// <summary> /// Leaves the current game /// </summary> public void leaveGame(int gameNum) { messager.AddMessages(new LeaveGame(username)); messager.SendMessages(client); currGame = tempCurrGame = null; }
private void ProcessGameCreate(byte[] msg, int currIndex) { string userHost; Game newGame = new Game(); currIndex++; StringBuilder s = new StringBuilder(); while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); userHost = s.ToString(); User host = users.GetUserFromName(userHost); newGame.host = host; newGame.gameHost = s.ToString(); currIndex++; s.Clear(); while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); newGame.name = s.ToString(); if (host == null) return; if (host.Category.Equals("Buddies")) KailleraTrayManager.Instance.handleTrayEvent(TrayFlags.PopValues.gameCreated, host, newGame.name); if (users.GetUserFromName(username).Equals(host)) { currGame = newGame; } s.Clear(); currIndex++; while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); newGame.emuName = s.ToString(); currIndex++; newGame.id = BitConverter.ToInt32(msg, currIndex); games.AddGame(newGame); gamesChanged(games); GUIManager.UpdateGames(games); }
private void ProcessExistingPlayers(byte[] msg, int currIndex) { currIndex+=2; int numUsers = BitConverter.ToInt32(msg, currIndex); currIndex += 4; //The server sends the name, ping, id, and connection //of each user in game - but we should already have //this information if we match the name to the user instance. //If game contains a user that server has not sent yet, //this fails, but we will try without it for (int i = 0; i < numUsers; i++) { StringBuilder s = new StringBuilder(); while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); string username = s.ToString(); currGame = tempCurrGame; currGame.users.AddUser(users.GetUserFromName(username)); currIndex += 1 + 4 + 2 + 1; //null, ping, id, connection } joinedGameSuccess(currGame); }
private void ProcessGameCreate(byte[] msg, int currIndex) { Game newGame = new Game(); currIndex++; StringBuilder s = new StringBuilder(); while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); User host = users.GetUserFromName(s.ToString()); newGame.host = host; currIndex++; s.Clear(); while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); newGame.name = s.ToString(); s.Clear(); currIndex++; while (msg[currIndex] != 0) s.Append((char)msg[currIndex++]); newGame.emuName = s.ToString(); currIndex++; newGame.id = BitConverter.ToInt32(msg, currIndex); games.AddGame(newGame); GUIManager.UpdateGames(games); }
public void RemoveGame(Game game) { numGames--; games.Remove(game); }
public void AddGame(Game game) { numGames++; games.Add(game); }