private void Test() { Game g = new Game(); PropertyBag p = new PropertyBag(); g.Properties = p; g.Owner = -1; TurnedGameServerGame tg = new TurnedGameServerGame(g); string msg =""; CharacterInfo ci1 = new CharacterInfo(); ci1.ID = 1; ci1.CharacterName = "Alpha"; ServerCharacterInfo t1 = new ServerCharacterInfo(ci1); tg.AddPlayer(t1, ref msg); CharacterInfo ci2 = new CharacterInfo(); ci2.ID = 2; ci2.CharacterName = "Bravo"; ServerCharacterInfo t2 = new ServerCharacterInfo(ci2); tg.AddPlayer(t2, ref msg); CharacterInfo ci3 = new CharacterInfo(); ci3.ID = 3; ci3.CharacterName = "Charly"; ServerCharacterInfo t3 = new ServerCharacterInfo(ci3); tg.AddPlayer(t3, ref msg); string msg2 =""; tg.StartGame(ref msg2, true); }
/* Sequence of events: Start Game OnBeforeGameStart OnGameStarted * OnBeforeRoundStart OnRoundStarted OnBeforeNextTurn OnNextTurn OnBeforePhaseStart OnPhaseStart OnBeforePhaseEnd OnPhaseEnd OnBeforePhaseStart... OnBeforeTurnEnd OnTurnEnded OnBeforeNextTurn... OnBeforeRoundEnd OnRoundEnded OnBeforeRoundStart... * OnBeforeGameEnd OnGameEnded */ public TurnedGameServerGame(Game g) : base(g) { m_GamePhaseSequencer = new GameSequencer(this); m_GamePhaseSequencer.ItemExecuted += new Action<IGameSequencerItem, bool, string>(GamePhaseSequencer_ItemExecuted); m_GamePhaseSequencer.ItemResponseTimerStarted += new Action<IGameSequencerItem>(GamePhaseSequencer_ItemResponseTimerStarted); }
public override bool DeSerialize(byte[] data, Pointer p) { base.DeSerialize(data, p); bool haveGame = BitPacker.GetBool(data, p); if(haveGame) { TheGame = BitPacker.GetComponent(data, p, false) as Game; } else { TheGame = null; } StillLooking = BitPacker.GetBool(data, p); return true; }
public ClientGame(Game g, LobbyClient client, ClientGameServerOutboundConnection con) { Connection = con; this.Client = client; this.AbandonedTimestamp = g.AbandonedTimestamp; this.Players = g.Players; this.GameID = g.GameID; this.IsShuttingDown = g.IsShuttingDown; this.Observers = g.Observers; this.Owner = g.Owner; this.Properties = g.Properties; RegisterGamePacketHandler((int)LobbyGameMessageSubType.GameInfoNotification, OnGameInfoNotification); RegisterGamePacketHandler((int)LobbyGameMessageSubType.GamePropertiesUpdateNotification, OnGamePropertiesUpdate); RegisterGamePacketHandler((int)LobbyGameMessageSubType.Chat, OnGameChat); RegisterGamePacketHandler((int)LobbyGameMessageSubType.NewOwner, OnNewGameOwner); }
/// <summary> /// Override to add custom game search data to the Game object for player game search. /// </summary> /// <param name="g">the game object as sent to the player</param> /// <param name="r">The data row containing all the data for this game</param> protected virtual void OnGameSearchResultTransform(Game g, DataRow r) { }
private void OnQuickMatchRequest(INetworkConnection con, Packet gmsg) { PacketQuickMatchResult note = (PacketQuickMatchResult)CreatePacket((int)LobbyPacketType.QuickMatchResult, 0, false, false); gmsg.ReplyPacket = note; if (!ValidateHasCurrentCharacter()) { note.ReplyMessage = "You must select a character before you can get a quick match ."; note.ReplyCode = ReplyType.Failure; return; } PacketGenericMessage gp = gmsg as PacketGenericMessage; string msg = ""; gp.Parms.SetProperty("QuickMatch", true); DataTable dt = DB.Instance.Lobby_GetQuickMatch(gp.Parms, out msg); bool gotRowCount = false; if (dt != null) { // Transform data result into game object foreach (DataRow r in dt.Rows) { note.ReplyCode = ReplyType.OK; Game g = new Game(); g.GameID = (Guid)r["GameID"]; g.Started = (bool)r["InProgress"]; g.MaxPlayers = (int)r["MaxPlayersAllowed"]; g.Name = (string)r["GameName"]; g.Properties.SetProperty("IsPrivate", (bool)r["IsPrivate"]); g.Properties.SetProperty("PlayerCount", (int)r["CurrentPlayers"]); // allow custom searches to add their additional data to the game object OnQuickMatchGameSearchResultTransform(g, r); note.TheGame = g; } } }
private void OnGameListingRequest(INetworkConnection con, Packet gmsg) { PacketMatchRefresh note = (PacketMatchRefresh)CreatePacket((int)LobbyPacketType.MatchRefresh, 0, false, false); note.IsServerPacket = false; note.IsRefresh = true; note.ReplyCode = ReplyType.OK; note.Kinds.Add(MatchNotificationType.ListingRefresh); note.TargetPlayers.Add(null); gmsg.ReplyPacket = note; if (!ValidateHasCurrentCharacter()) { note.ReplyMessage = "You must select a character before you can receive a content listing."; note.ReplyCode = ReplyType.Failure; return; } PacketGenericMessage gp = gmsg as PacketGenericMessage; int page = gp.Parms.GetIntProperty("Page").GetValueOrDefault(0); int numPerPage = gp.Parms.GetIntProperty("NumPerPage").GetValueOrDefault(50); bool includeInProgress = gp.Parms.GetBoolProperty("IncludeInProgress").GetValueOrDefault(true); int minPlayersAllowed = gp.Parms.GetIntProperty("MinPlayersAllowed").GetValueOrDefault(0); string msg = ""; DataTable dt = DB.Instance.Lobby_GetGameListing(page, numPerPage, "", includeInProgress, minPlayersAllowed, gp.Parms, out msg); bool gotRowCount = false; if (dt != null) { // Transform data result into game object foreach (DataRow r in dt.Rows) { if (!gotRowCount) { gotRowCount = true; note.Parms.SetProperty("TotalGames", (int)r["TotalRows"]); } Game g = new Game(); g.GameID = (Guid)r["GameID"]; g.Started = (bool)r["InProgress"]; g.MaxPlayers = (int)r["MaxPlayersAllowed"]; g.Name = (string)r["GameName"]; g.Properties.SetProperty("IsPrivate", (bool)r["IsPrivate"]); g.Properties.SetProperty("PlayerCount", (int)r["CurrentPlayers"]); // allow custom searches to add their additional data to the game object OnGameSearchResultTransform(g, r); note.TheGames.Add(g); } } }
/// <summary> /// Gets called when the base LobbyClient creates the CurrentGame object using the base game data /// that was received from the Central server. If you want to use a derivative Game object instead of the /// standard ClientGame type, instantiate it here and return it. /// </summary> /// <param name="baseData"></param> /// <returns></returns> protected virtual ClientGame OnCreateCurrentGameObject(Game baseData) { return new ClientGame(baseData, this, m_GameServer); }
private void FireQuickMatchResultArrived(bool result, string msg, LobbyClientCentralServerOutboundConnection sender, Game g) { if (QuickMatchResultArrivedInvoker != null) { QuickMatchResultArrivedInvoker(result, msg, sender, g); } }
private void OnCentralServer_PlayerJoined(bool isFromCentralServer, bool isFromContentServer, bool success, string msg, ClientServerOutboundConnection sender, CharacterInfo player, Game theGame, PropertyBag parms) { if (theGame == null) { msg += "Unknow game: null"; success = false; } if (success) { m_PendingGameToJoin = theGame; } FirePlayerJoinedGame(true, false, success, msg, sender, player, theGame, parms); // let's disconnect from central and join the GS, if Central says it's okay. if (success) { Log.LogMsg("Successfully joined a game. Waiting for transfer confirmation. "); } else { Log.LogMsg("Failed to join content instance. " + msg); } }
private void FireContentCreateGameRequestResolved(bool result, string msg, ClientServerOutboundConnection con, Game g) { if (ContentCreateGameRequestResolvedInvoker != null) { ContentCreateGameRequestResolvedInvoker(result, msg, con, g); } }
private void OnGameServer_PlayerRemoved(string msg, ClientServerOutboundConnection sender, CharacterInfo player, Game theGame, PropertyBag parms) { FirePlayerRemovedFromGame(msg, sender, player, theGame, parms); }
private void OnGameServer_PlayerJoined(bool isFromCentralServer, bool isFromContentServer, bool success, string msg, ClientServerOutboundConnection sender, CharacterInfo player, Game theGame, PropertyBag parms) { FirePlayerJoinedGame(false, true, success, msg, sender, player, theGame, parms); }
void OnGameServer_JoinResult(bool result, string msg, ClientServerOutboundConnection sender, Game g) { FireGameServerJoinGameResolved(result, msg, sender, g); }
ClientGame OnGameServer_GameActivating(LobbyClientGameServerOutboundConnection con, Game gameData) { return OnCreateCurrentGameObject(gameData); }
private void OnGameServer_CreateGameRequestResolved(bool success, string msg, ClientServerOutboundConnection sender, Game newGame) { FireContentGameCreationRequestResolved(success, msg, sender, newGame); }
void OnCentralServer_QuickMatchResultArrived(bool result, string msg, LobbyClientCentralServerOutboundConnection sender, Game g) { m_QuickMatchGame = g; FireQuickMatchResultArrived(result, msg, this); }
protected override GameServerGame OnCreateNewGameServerGame(Game game) { TurnedGameServerGame g = new TurnedGameServerGame(game); game.Decorator = g; return g; }
private void FireJoinGameResolved(bool result, string msg, ClientServerOutboundConnection con, Game g) { if (JoinGameResolvedInvoker != null) { JoinGameResolvedInvoker(result, msg, con, g); } }
private void FirePlayerRemoved(string msg, ClientServerOutboundConnection con, CharacterInfo player, Game g, PropertyBag parms) { if (PlayerRemovedInvoker != null) { PlayerRemovedInvoker(msg, con, player, g, parms); } }
private ClientGame FireGameActivating(LobbyClientGameServerOutboundConnection con, Game gameData) { if (GameActivatingInvoker != null) { return GameActivatingInvoker(con, gameData); } return null; }
private void OnCentralServer_CreateGameRequestResolved(bool success, string msg, ClientServerOutboundConnection sender, Game newGame) { if (success && newGame != null) { m_PendingGameToJoin = newGame; } FireCentralGameCreationRequestResolved(success, msg, sender, newGame); }
private void FirePlayerJoined(bool isFromCentralServer, bool isFromContentServer, bool result, string msg, ClientServerOutboundConnection con, CharacterInfo player, Game g, PropertyBag parms) { if (PlayerJoinedInvoker != null) { PlayerJoinedInvoker(isFromCentralServer, isFromContentServer, result, msg, con, player, g, parms); } }
protected virtual GameServerGame OnCreateNewGameServerGame(Game game) { GameServerGame g = new GameServerGame(game); game.Decorator = g; return g; }
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 FireCentralCreateGameRequestResolved(bool result, string msg, ClientServerOutboundConnection con, Game newGame) { if (CentralCreateGameRequestResolvedInvoker != null) { CentralCreateGameRequestResolvedInvoker(result, msg, con, newGame); } }