public void SendMatchChangeNotificationToPlayers(MatchNotificationType kind, ServerCharacterInfo targetPlayer, string text, bool synchClientGameObject) { PacketMatchNotification p = new PacketMatchNotification(); p.PacketTypeID = (int)LobbyPacketType.MatchNotification; p.Kind = kind; p.TheGame = synchClientGameObject? Game : null; p.TheGameID = Game.GameID; if (targetPlayer != null) { p.TargetPlayer = targetPlayer.CharacterInfo; } p.ReplyCode = ReplyType.OK; p.ReplyMessage = text; /* * if (p.Kind == MatchNotificationType.MatchEnded) * { * // add this particular message to the PFX queue, to make sure that the EndMessage/Disconnect&Transfer happen in the property order * Task t = new Task((state) => * { * BroadcastToPlayersInGame(p, true); * }, "BroadcastToPlayersInGame: Match Ended", TaskCreationOptions.LongRunning); * m_NetQ.AddTask(t); * } * else */ { BroadcastToPlayersInGame(p, true); } }
private void OnObserverAdded(PacketMatchNotification note) { if (CurrentGame == null) { return; } // Update Observer objects lock (CurrentGame.AllObserversSyncRoot) { if (note.TheGame != null) // sync all observer objects { CurrentGame.Observers = note.TheGame.Observers; } if (note.TargetPlayer != null) // update target player object { // update the toon with the incoming data CurrentGame.Observers.Remove(note.TargetPlayer.ID); CurrentGame.Observers.Add(note.TargetPlayer.ID, note.TargetPlayer); } CurrentGame.AllObservers = (List <ICharacterInfo>)CurrentGame.Observers.Values.ToList <ICharacterInfo>(); } Log.LogMsg("Player [" + note.TargetPlayer != null ? note.TargetPlayer.CharacterName : "Some Player" + "] IS OBSERVING game [" + note.TheGameID + "]"); FireObserverJoined(false, true, note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TargetPlayer as CharacterInfo, note.TheGame as Game, note.Parms); }
private void OnObserverRemoved(PacketMatchNotification note) { if (CurrentGame == null) { return; } // Update Observer objects lock (CurrentGame.AllObserversSyncRoot) { if (note.TheGame != null) // sync all observer objects { CurrentGame.Observers = note.TheGame.Observers; } if (note.TargetPlayer != null) // update target player object { // update the toon with the incoming data CurrentGame.Observers.Remove(note.TargetPlayer.ID); } CurrentGame.AllObservers = (List <ICharacterInfo>)CurrentGame.Observers.Values.ToList <ICharacterInfo>(); } Log.LogMsg("Player [" + note.TargetPlayer != null ? note.TargetPlayer.CharacterName : "Some Player" + "] STOPPED OBSERVING game [" + note.TheGameID + "]"); FireObserverRemoved(note.ReplyMessage, this, note.TargetPlayer as CharacterInfo, note.TheGame as Game, note.Parms); if (Client.Instance.User != null && Client.Instance.User.CurrentCharacter != null) { if (Client.Instance.User.CurrentCharacter.ID == note.TargetPlayer.ID) // did I get removed? { // yes, i was removed from the game. we are no longer part of a game. CurrentGame = null; } } }
private void OnGameStarted(PacketMatchNotification note) { if (CurrentGame != null) { foreach (ICharacterInfo ci in CurrentGame.AllPlayers) { CurrentGame.EverActivePlayers.Remove(ci.ID); CurrentGame.EverActivePlayers.Add(ci.ID, ci); } } FireGameStartReply(this, true, note.ReplyMessage); }
protected virtual void OnGameCreated(PacketMatchNotification note) { if (note.TheGame != null) { Log.LogMsg("Game [" + note.TheGame.GameID.ToString() + "] creation permission granted?: " + note.ReplyCode.ToString() + " - " + note.ReplyMessage); } else { Log.LogMsg("Game creation permission granted? : " + note.ReplyCode.ToString() + " - " + note.ReplyMessage); } FireCentralCreateGameRequestResolved(note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TheGame as Game); }
private void OnPlayerAddedToGame(PacketMatchNotification note) { if (CurrentGame == null) { return; } // Update player objects lock (CurrentGame.AllPlayersSyncRoot) { if (note.TheGame != null) // sync all player objects { CurrentGame.Players = note.TheGame.Players; if (CurrentGame.CurrentGameState == GameState.Started) { foreach (ICharacterInfo ci in note.TheGame.Players.Values) { CurrentGame.EverActivePlayers.Remove(ci.ID); CurrentGame.EverActivePlayers.Add(ci.ID, ci); } } } if (note.TargetPlayer != null) // update target player object { // update the toon with the incoming data CurrentGame.Players.Remove(note.TargetPlayer.ID); CurrentGame.Players.Add(note.TargetPlayer.ID, note.TargetPlayer); if (CurrentGame.CurrentGameState == GameState.Started) { CurrentGame.EverActivePlayers.Remove(note.TargetPlayer.ID); CurrentGame.EverActivePlayers.Add(note.TargetPlayer.ID, note.TargetPlayer); } } CurrentGame.AllPlayers = (List <ICharacterInfo>)CurrentGame.Players.Values.ToList <ICharacterInfo>(); } if (Client.Instance.User.CurrentCharacter.ID == note.TargetPlayer.ID) // was this message about me? { // Join message about us only come as a result of our join requests. Therefore, we must fire the following event... FireJoinGameResolved(note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TheGame as Game); } Log.LogMsg("Player [" + note.TargetPlayer != null ? note.TargetPlayer.CharacterName : "Some Player" + "] JOINED game [" + note.TheGameID + "]"); FirePlayerJoined(false, true, note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TargetPlayer as CharacterInfo, note.TheGame as Game, note.Parms); }
protected void OnGameNotification(INetworkConnection con, Packet p) { PacketMatchNotification note = p as PacketMatchNotification; if (CurrentGame != null) { if (CurrentGame.GameID != note.TheGameID) { return; } } switch (note.Kind) { case MatchNotificationType.PlayerRemoved: OnPlayerRemovedFromGame(note); break; case MatchNotificationType.PlayerAdded: OnPlayerAddedToGame(note); break; case MatchNotificationType.MatchCreated: OnGameCreated(note); break; case MatchNotificationType.ObserverAdded: OnObserverAdded(note); break; case MatchNotificationType.ObserverRemoved: OnObserverRemoved(note); break; case MatchNotificationType.MatchStarted: OnGameStarted(note); break; case MatchNotificationType.MatchEnded: OnGameEnded(note); break; default: Log.LogMsg("Unhandled packet match notification [" + note.Kind.ToString() + "]"); break; } }
public void SendMatchChangeNotificationToPlayer(ServerCharacterInfo toon, MatchNotificationType kind, ServerCharacterInfo targetPlayer, string text, bool synchClientGameObject) { PacketMatchNotification p = new PacketMatchNotification(); p.PacketTypeID = (int)LobbyPacketType.MatchNotification; p.Kind = kind; p.TheGame = synchClientGameObject ? Game : null; p.TheGameID = Game.GameID; if (targetPlayer != null) { p.TargetPlayer = targetPlayer.CharacterInfo; } p.ReplyCode = ReplyType.OK; p.ReplyMessage = text; SendPacketToPlayer(toon, p); }
private void OnPlayerJoinGame(INetworkConnection con, Packet gmsg) { PacketGenericMessage genMsg = gmsg as PacketGenericMessage; if (!ValidateHasCurrentCharacter()) { return; } Guid gameId = genMsg.Parms.GetGuidProperty((int)PropertyID.GameId); ServerCharacterInfo ci = ServerUser.CurrentCharacter; string address = ""; int port = 0; string name = ""; Log1.Logger(MyServer.ServerUserID).Info(string.Format("Player {0} requesting join content '{1}'...", ServerUser.AccountName, gameId.ToString())); if (DB.Instance.Lobby_GetGameServer(gameId, out address, out port, out name) && address.Length > 0 && port > 0) { Log.LogMsg(string.Format("Transferring Player {0} to join content '{1}' on server @ {2} ...", ServerUser.AccountName, gameId.ToString(), address)); PacketMatchNotification note = (PacketMatchNotification)CreatePacket((int)LobbyPacketType.MatchNotification, 0, false, false); note.Kind = MatchNotificationType.PlayerAdded; note.TargetPlayer = ci.CharacterInfo; note.Parms = genMsg.Parms; note.ReplyCode = ReplyType.OK; Send(note); ServerUser.TransferToServerUnassisted(address, port, gameId, name, name); } else { Log.LogMsg(string.Format("Player {0} failed to join content '{1}' : {2} ...", ServerUser.AccountName, gameId.ToString(), "Couldn't find game. Join canceled.")); PacketMatchNotification note = (PacketMatchNotification)CreatePacket((int)LobbyPacketType.MatchNotification, 0, false, false); note.ReplyMessage = "Game couldn't be found. Strange..."; note.Kind = MatchNotificationType.PlayerAdded; note.TargetPlayer = ci.CharacterInfo; note.Parms = genMsg.Parms; note.ReplyCode = ReplyType.Failure; genMsg.ReplyPacket = note; return; } }
protected void OnGameNotification(INetworkConnection con, Packet p) { PacketMatchNotification note = p as PacketMatchNotification; switch (note.Kind) { case MatchNotificationType.MatchCreated: OnGameCreated(note); break; case MatchNotificationType.PlayerAdded: OnPlayerAdded(note); break; default: Log.LogMsg("Unhandled packet match notification [" + note.Kind.ToString() + "]"); break; } }
private void OnCreateNewGame(INetworkConnection con, Packet gmsg) { PacketGenericMessage genMsg = gmsg as PacketGenericMessage; PacketMatchNotification note = (PacketMatchNotification)CreatePacket((int)LobbyPacketType.MatchNotification, 0, false, false); note.Kind = MatchNotificationType.MatchCreated; note.NeedsReply = false; if (!ValidateHasCurrentCharacter()) { genMsg.ReplyPacket = note; note.ReplyMessage = "You must select a character before you can create a new game."; note.ReplyCode = ReplyType.Failure; return; } // // <h2 style="text-align: center"><span style="color: #993300;"><a href="http://www.survivalnotes.org/content/category/fire"><span style="color: #993300;">Latest Entries</span></a> <a href="http://www.survivalnotes.org/content/category/fire?r_sortby=highest_rated&r_orderby=desc"><span style="color: #993300;">Highest Rated Entries</span></a></span></h2> // <h2 style="text-align: center"><span style="color: #993300;"><a href="http://www.survivalnotes.org/content/category/fire"><span style="color: #993300;">Latest Entries</span></a> <a href="http://www.survivalnotes.org/content/category/fire?r_sortby=highest_rated&r_orderby=desc"><span style="color: #993300;">Highest Rated Entries</span></a></span></h2> // Log1.Logger(MyServer.ServerUserID).Info(string.Format("Player {0} requesting create new game '{1}' ...", ServerUser.AccountName, genMsg.Parms.GetStringProperty((int)PropertyID.Name))); string msg = ""; GameServerInfo <OutboundServerConnection> gsi = RequestCreateNewGameServer(out msg); genMsg.ReplyPacket = note; note.ReplyMessage = msg; if (gsi == null) { // Failed. Either no servers online, or they are full. note.ReplyCode = ReplyType.Failure; return; } else { // Contact that server and request a game be created. note.ReplyCode = ReplyType.OK; ServerUser.TransferToServerUnassisted(gsi.IP, gsi.Port, Guid.Empty, gsi.Name, gsi.UserID); } }
private void OnGameEnded(PacketMatchNotification note) { FireGameEnded(this, note.TheGame.Properties, note.ReplyMessage); this.CurrentGame = null; }
protected virtual void OnGameCreated(PacketMatchNotification note) { if (note.TheGame != null) { Log.LogMsg("Game [" + note.TheGame.GameID.ToString() + "] created: " + note.ReplyCode.ToString() + " - " + note.ReplyMessage); } else { Log.LogMsg("Game created: " + note.ReplyCode.ToString() + " - " + note.ReplyMessage); } FireContentCreateGameRequestResolved(note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TheGame as Game); }
protected override bool OnPlayerLoginResolved(PacketLoginRequest login, bool result, ref string msg) { ///............. if (!base.OnPlayerLoginResolved(login, result, ref msg)) { return(result); } if (ServerUser.CurrentCharacter == null) { msg = "Can't join or create games without an active character."; return(false); } Guid gameId = Guid.Empty; GameServerGame sg = null; PacketMatchNotification note = (PacketMatchNotification)CreatePacket((int)LobbyPacketType.MatchNotification, 0, false, false); // Requesting to join as observer? bool observeOnly = login.Parms.GetBoolProperty("Observe").GetValueOrDefault(false); if (login.Parms.GetBoolProperty("IsNewGame").GetValueOrDefault(false)) { Log1.Logger("Server").Debug("Player [" + ServerUser.AccountName + "] logging in with NEW GAME request."); note.Kind = MatchNotificationType.MatchCreated; note.NeedsReply = false; note.ReplyCode = ReplyType.Failure; // new game. create it. Game g = new Game(); g.Name = login.Parms.GetStringProperty((int)PropertyID.Name); g.MaxPlayers = login.Parms.GetIntProperty((int)PropertyID.MaxPlayers).GetValueOrDefault(1); g.MaxObservers = login.Parms.GetIntProperty((int)PropertyID.MaxObservers).GetValueOrDefault(0); g.Owner = ServerUser.CurrentCharacter.ID; // Create the actual game object, specific to the game type we are serving. sg = OnCreateNewGameServerGame(g); //sg = null; if (sg != null) { // Track the new game object on this server if (!GameManager.Instance.CreateNewGame(sg, true)) { msg = "Failed to create game on server. Internal server error."; note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } // Report the new game in the database if (!DB.Instance.Lobby_TrackGameForServer(MyServer.ServerUserID, sg, DateTime.UtcNow, ServerUser)) { msg = "Failed to register the game in the database. Internal server error."; note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } // Update player counts for this server, based on the expected player count for the new game. if (DB.Instance.Server_Register(MyServer.ServerUserID, MyServer.ServerAddress, MyServer.ListenOnPort, DateTime.UtcNow, "content", ConnectionManager.PaddedConnectionCount, MyServer.MaxConnections)) { note.ReplyCode = ReplyType.OK; } else { DB.Instance.Lobby_UntrackGameForServer(sg.GameID); note.ReplyMessage = "Failed to register game with master game listing. Internal server error."; Send(note); TransferToLobbyOrDisconnect(); return(true); } } else { msg = "Unable to create game at this time."; Log1.Logger("Server").Debug("Failed to create NEW GAME for player [" + ServerUser.AccountName + "]."); login.ReplyPacket.Parms.SetProperty("CreateReply", msg); note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } } else // it's a join - get game reference from existing games table { Log1.Logger("Server").Debug("Player [" + ServerUser.AccountName + "] logging in with request to JOIN EXISTING game. [Observe = " + observeOnly.ToString() + "]"); note = (PacketMatchNotification)CreatePacket((int)LobbyPacketType.MatchNotification, 0, false, false); if (observeOnly) { note.Kind = MatchNotificationType.ObserverAdded; } else { note.Kind = MatchNotificationType.PlayerAdded; } note.TargetPlayer = ServerUser.CurrentCharacter.CharacterInfo; note.ReplyCode = ReplyType.Failure; Guid targetGame = login.Parms.GetGuidProperty((int)PropertyID.GameId); if (targetGame == Guid.Empty) { msg = "Failed to join game. No target game specified."; Log1.Logger("Server").Debug("Player [" + ServerUser.AccountName + "] failed to JOIN EXISTING game. No target game specified in join request."); note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } if (!GameManager.Instance.GetGame(targetGame, out sg)) { Log1.Logger("Server").Debug("Player [" + ServerUser.AccountName + "] failed to JOIN EXISTING game. Target game specified does not currently exist."); msg = "Failed to join game. Target game [" + targetGame.ToString() + "] does not currently exist on [" + MyServer.ServerUserID + "]."; note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } } if (sg == null) { Log1.Logger("Server").Debug("Player [" + ServerUser.AccountName + "] failed to locate game. Internal Server Error."); msg = "Unable to locate game. Internal Server Error."; // should never happen note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } // join game as player or observer if (!observeOnly && sg.AddPlayer(ServerUser.CurrentCharacter, ref msg)) { login.ReplyPacket.Parms.SetProperty("TargetGame", (ISerializableWispObject)sg.Game); RegisterPacketHandler((int)PacketType.PacketGenericMessage, (int)GenericLobbyMessageType.RequestStartGame, OnRequestStartGame); } else if (observeOnly && sg.AddObserver(ServerUser.CurrentCharacter, ref msg)) { login.ReplyPacket.Parms.SetProperty("TargetGame", (ISerializableWispObject)sg.Game); } else { msg = "Unable to join game."; note.ReplyMessage = msg; Send(note); TransferToLobbyOrDisconnect(); return(true); } RegisterPacketHandler((int)PacketType.PacketGenericMessage, (int)GenericLobbyMessageType.LeaveGame, OnPlayerLeaveGame); return(result); }
private void OnPlayerAddedToGame(PacketMatchNotification note) { if (CurrentGame == null) { return; } // Update player objects lock (CurrentGame.AllPlayersSyncRoot) { if (note.TheGame != null) // sync all player objects { CurrentGame.Players = note.TheGame.Players; if (CurrentGame.CurrentGameState == GameState.Started) { foreach (ICharacterInfo ci in note.TheGame.Players.Values) { CurrentGame.EverActivePlayers.Remove(ci.ID); CurrentGame.EverActivePlayers.Add(ci.ID, ci); } } } if (note.TargetPlayer != null) // update target player object { // update the toon with the incoming data CurrentGame.Players.Remove(note.TargetPlayer.ID); CurrentGame.Players.Add(note.TargetPlayer.ID, note.TargetPlayer); if (CurrentGame.CurrentGameState == GameState.Started) { CurrentGame.EverActivePlayers.Remove(note.TargetPlayer.ID); CurrentGame.EverActivePlayers.Add(note.TargetPlayer.ID, note.TargetPlayer); } } CurrentGame.AllPlayers = (List<ICharacterInfo>)CurrentGame.Players.Values.ToList<ICharacterInfo>(); } if (Client.Instance.User.CurrentCharacter.ID == note.TargetPlayer.ID) // was this message about me? { // Join message about us only come as a result of our join requests. Therefore, we must fire the following event... FireJoinGameResolved(note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TheGame as Game); } Log.LogMsg("Player [" + note.TargetPlayer != null ? note.TargetPlayer.CharacterName : "Some Player" + "] JOINED game [" + note.TheGameID + "]"); FirePlayerJoined(false, true, note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TargetPlayer as CharacterInfo, note.TheGame as Game, note.Parms); }
private void OnObserverAdded(PacketMatchNotification note) { if (CurrentGame == null) { return; } // Update Observer objects lock (CurrentGame.AllObserversSyncRoot) { if (note.TheGame != null) // sync all observer objects { CurrentGame.Observers = note.TheGame.Observers; } if (note.TargetPlayer != null) // update target player object { // update the toon with the incoming data CurrentGame.Observers.Remove(note.TargetPlayer.ID); CurrentGame.Observers.Add(note.TargetPlayer.ID, note.TargetPlayer); } CurrentGame.AllObservers = (List<ICharacterInfo>)CurrentGame.Observers.Values.ToList<ICharacterInfo>(); } Log.LogMsg("Player [" + note.TargetPlayer != null ? note.TargetPlayer.CharacterName : "Some Player" + "] IS OBSERVING game [" + note.TheGameID + "]"); FireObserverJoined(false, true, note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TargetPlayer as CharacterInfo, note.TheGame as Game, note.Parms); }
private void OnPlayerAdded(PacketMatchNotification note) { // PlayerAdded messages from Central only come in responds to a join request - there are no actual games hosted on Central. // Therefore, we interpret the PlayerAdded message a JoinGameRequest result. FireJoinGameResolved(note.ReplyCode == ReplyType.OK, note.ReplyMessage, this, note.TheGame as Game); }
private void OnPlayerRemovedFromGame(PacketMatchNotification note) { if (CurrentGame == null) { return; } // Update player objects lock (CurrentGame.AllPlayersSyncRoot) { if (note.TheGame != null) // sync all player objects { CurrentGame.Players = note.TheGame.Players; } if (note.TargetPlayer != null) // update target player object { // update the toon with the incoming data CurrentGame.Players.Remove(note.TargetPlayer.ID); } CurrentGame.AllPlayers = (List<ICharacterInfo>)CurrentGame.Players.Values.ToList<ICharacterInfo>(); } Log.LogMsg("Player [" + note.TargetPlayer != null ? note.TargetPlayer.CharacterName : "Some Player" + "] STOPPED PLAYING game [" + note.TheGameID + "]"); FirePlayerRemoved( note.ReplyMessage, this, note.TargetPlayer as CharacterInfo, note.TheGame as Game, note.Parms); if (Client.Instance.User != null && Client.Instance.User.CurrentCharacter != null) { if (Client.Instance.User.CurrentCharacter.ID == note.TargetPlayer.ID) // did I get removed? { // yes, i was removed from the game. we are no longer part of a game. CurrentGame = null; } } }