Esempio n. 1
0
        /// <summary>
        /// Adds a packet to the queue for serial processing.
        /// </summary>
        /// <param name="con">the connection which sent the packet</param>
        /// <param name="msg">the packet</param>
        public void AddGamePacketForProcessing(GSLobbyInboundPlayerConnection con, PacketGameMessage msg)
        {
            Action <object> lambda = (state) =>
            {
                Action <ServerUser, PacketGameMessage> handler = m_PacketHandlers.GetHandlerDelegate(msg.PacketSubTypeID);
                if (handler != null && OnBeforeHandleGamePacket(con.ServerUser, msg))
                {
                    try
                    {
                        handler(con.ServerUser, msg);
                    }
                    catch (Exception e)
                    {
                        Log.LogMsg("Exception thrown whilst processing game packet type " + msg.PacketTypeID.ToString() + ", sub-type " + msg.PacketSubTypeID + ". Object = " + this.GetType().ToString() + ", Message: " + e.Message + ". Stack:\r\n " + e.StackTrace);
                    }

                    con.OnAfterPacketProcessed(msg);
                    return;
                }
                con.KillConnection("Did not have a registered game packet handler for game packet. " + msg.PacketTypeID.ToString() + ", SubType " + msg.PacketSubTypeID.ToString() + ". ");
            };

            // if we're not processing packets immediately, then this method (AddGamePacketForProcessing) is being called as part of  a tight networking processing loop
            // which is executed serially, so we need to NOT queue the packet in that case and just run it
            if (!con.ProcessIncomingPacketsImmediately)
            {
                lambda(null);
            }
            else
            {
                Task t = new Task(lambda, "Game [" + GameID.ToString() + "] Process game packet " + msg.PacketSubTypeID.ToString(), TaskCreationOptions.LongRunning);
                m_NetQ.AddTask(t);
            }
        }
Esempio n. 2
0
        protected virtual void OnPlayerChat(ServerUser fromPlayer, PacketGameMessage msg)
        {
            // Game messages are already queued... should not need to queue them manually
            //Task t = new Task((state) =>
            {
                int    targetPlayer = msg.Parms.GetIntProperty("target").GetValueOrDefault(-1);
                string text         = msg.Parms.GetStringProperty("text");
                if (text == null || text.Length < 1)
                {
                    return;
                }

                msg.Parms.SetProperty("sender", fromPlayer.CurrentCharacter.CharacterInfo as ISerializableWispObject);

                if (targetPlayer < 0)
                {
                    // Public chat
                    BroadcastToPlayersInGame(msg, true, fromPlayer.CurrentCharacter);
                    return;
                }

                if (IsPlayerPartOfGame(targetPlayer))
                {
                    ServerCharacterInfo sci = GetCharacter(targetPlayer) as ServerCharacterInfo;
                    SendPacketToPlayer(sci, msg);
                }
            }//, "Chat from player " + fromPlayer.CurrentCharacter.CharacterName, TaskCreationOptions.PreferFairness);
             //m_NetQ.AddTask(t);
        }
Esempio n. 3
0
        /// <summary>
        /// While the game is in the lobby, you may request a new seat/team/etc.  The exact seat/team designation depends on the type of game being played.
        /// </summary>
        /// <param name="props">the requested setup arrangement</param>
        public void RequestNewSeating(PropertyBag props)
        {
            PacketGameMessage seat = new PacketGameMessage();

            seat.PacketSubTypeID = (int)LobbyGameMessageSubType.SeatChangeRequest;
            seat.Parms           = props;
            Connection.Send(seat);
        }
Esempio n. 4
0
        /// <summary>
        /// Sends a generic PacketGameMessage of a specific sub type to a player
        /// </summary>
        /// <param name="msg">the message</param>
        /// <param name="includeObservers">if observers should be included</param>
        /// <param name="targetPlayers">explicit list of message targets, or null for everyone</param>
        public void SendGameMessageToPlayer(ServerCharacterInfo toon, int subType, PropertyBag props)
        {
            PacketGameMessage note = new PacketGameMessage();

            note.PacketSubTypeID = subType;
            note.Parms           = props;

            SendPacketToPlayer(toon, note);
        }
Esempio n. 5
0
 private void OnPlayerDone(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         PlayerDone(user.CurrentCharacter);
     }
     catch
     {
     }
 }
Esempio n. 6
0
        public void BroadcastGameMessage(int gameMessageType, PropertyBag props, bool includeObservers, bool isCompressed, bool isEncrypted)
        {
            PacketGameMessage msg = new PacketGameMessage();

            msg.IsCompressed    = isCompressed;
            msg.IsEncrypted     = isEncrypted;
            msg.PacketSubTypeID = gameMessageType;
            msg.Parms           = props;

            BroadcastToPlayersInGame(msg, true);
        }
Esempio n. 7
0
 protected override bool OnBeforeHandleGamePacket(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         return(IsPlayerPartOfGame(user.CurrentCharacter.ID));
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Signal to the server that we are done and are relinquishing control.
        /// </summary>
        public void PlayerDone()
        {
            if (!Client.GameServerReadyForPlay)
            {
                Log.LogMsg("Tried to send 'Player Done', but game server not ready.");
                return;
            }

            PacketGameMessage done = new PacketGameMessage();

            done.PacketSubTypeID = (int)TurnedGameMessageSubType.PlayerDone;
            Connection.Send(done);
        }
Esempio n. 9
0
        /// <summary>
        /// Sends a PacketGameMessage to the game server for this particular game.  All PacketGameMessages are handled serially on the server in the
        /// order that they were received.
        /// </summary>
        /// <param name="gamePacketSubType">packet type ID</param>
        /// <param name="parms">any paramters</param>
        public void SendGameMessage(int gamePacketSubType, PropertyBag parms = null)
        {
            if (!Client.GameServerReadyForPlay)
            {
                Log.LogMsg("Tried to send PacketGameMessage type [ " + gamePacketSubType.ToString() + "], but game server not ready.");
                return;
            }

            PacketGameMessage gm = new PacketGameMessage();

            gm.PacketSubTypeID = gamePacketSubType;
            gm.Parms           = parms;
            Connection.Send(gm);
        }
Esempio n. 10
0
        /// <summary>
        /// Send a chat message to the game.
        /// </summary>
        /// <param name="targetPlayer">-1 for public chat, character id to whisper</param>
        /// <param name="text">the text to send</param>
        public void SendChat(int targetPlayer, string text)
        {
            if (!Client.GameServerReadyForPlay)
            {
                Log.LogMsg("Tried to send 'Chat', but game server not ready.");
                return;
            }

            PacketGameMessage chat = new PacketGameMessage();

            chat.PacketSubTypeID = (int)LobbyGameMessageSubType.Chat;
            chat.Parms.SetProperty("target", targetPlayer);
            chat.Parms.SetProperty("text", text);
            Connection.Send(chat);
        }
Esempio n. 11
0
        protected virtual void OnPlayerClientLevelLoaded(ServerUser fromPlayer, PacketGameMessage msg)
        {
            float pLoaded = msg.Parms.GetSinglelProperty("PercentLoaded").GetValueOrDefault(0);

            Log1.Logger("Server").Debug(fromPlayer.CurrentCharacter.CharacterName + " loaded " + pLoaded + "%");
            Properties.SetProperty(fromPlayer.CurrentCharacter.ID.ToString() + "_clientloadpercent", pLoaded);
            bool stillWaiting = !m_Game.AllPlayerClientsLoaded();

            Log1.Logger("Server").Debug("Still waiting for clients to load: " + stillWaiting.ToString());
            if (!stillWaiting)
            {
                Log1.Logger("Server").Debug("Firing ALL CLIENTS LOADED");
                AllPlayerClientsLoaded();
            }
            m_Game.WaitingOnClientsToLoad = stillWaiting;
        }
Esempio n. 12
0
        protected virtual void OnNewGameOwner(INetworkConnection con, Packet msg)
        {
            PacketGameMessage gmsg = msg as PacketGameMessage;

            if (gmsg == null)
            {
                return;
            }

            int newOwner = gmsg.Parms.GetIntProperty("NewOwner").GetValueOrDefault(-1);

            if (newOwner != -1)
            {
                Owner = newOwner;
            }
        }
Esempio n. 13
0
        protected virtual void OnGameChat(INetworkConnection con, Packet msg)
        {
            PacketGameMessage gmsg = msg as PacketGameMessage;

            if (gmsg == null)
            {
                return;
            }

            CharacterInfo from   = gmsg.Parms.GetWispProperty("sender") as CharacterInfo;
            string        text   = gmsg.Parms.GetStringProperty("text");
            int           target = gmsg.Parms.GetIntProperty("target").GetValueOrDefault(-1);

            if (target == -1)
            {
                // public message
                AddMessage(FormatString(GameStringType.PlayerName, from.CharacterName + ": ") + FormatString(GameStringType.ChatText, text));
            }
            else
            {
                AddMessage(FormatString(GameStringType.PlayerName, from.CharacterName + " whispered to you: ") + FormatString(GameStringType.PrivateMessage, text));
                // private message
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Send a chat message to the game.
        /// </summary>
        /// <param name="targetPlayer">-1 for public chat, character id to whisper</param>
        /// <param name="text">the text to send</param>
        public void SendChat(int targetPlayer, string text)
        {
            if (!Client.GameServerReadyForPlay)
            {
                Log.LogMsg("Tried to send 'Chat', but game server not ready.");
                return;
            }

            PacketGameMessage chat = new PacketGameMessage();
            chat.PacketSubTypeID = (int)LobbyGameMessageSubType.Chat;
            chat.Parms.SetProperty("target", targetPlayer);
            chat.Parms.SetProperty("text", text);
            Connection.Send(chat);
        }
Esempio n. 15
0
 /// <summary>
 /// Adds a packet to the queue for serial processing.  If the con.ProcessPacketsImmediately is set to true, then we will not queue the packet
 /// but rather will execute the handler immediately.
 /// </summary>
 /// <param name="con">the connection which sent the packet</param>
 /// <param name="msg">the packet</param>
 public void HandleGamePacket(LobbyClientGameServerOutboundConnection con, PacketGameMessage msg)
 {
     HandlePacket(con, msg, m_PacketHandlers);
 }
Esempio n. 16
0
 protected virtual void OnPlayerSeatChangeRequest(ServerUser fromPlayer, PacketGameMessage msg)
 {
 }
Esempio n. 17
0
 /// <summary>
 /// Adds a packet to the queue for serial processing.  If the con.ProcessPacketsImmediately is set to true, then we will not queue the packet
 /// but rather will execute the handler immediately.
 /// </summary>
 /// <param name="con">the connection which sent the packet</param>
 /// <param name="msg">the packet</param>
 public void HandleGamePacket(LobbyClientGameServerOutboundConnection con, PacketGameMessage msg)
 {
     HandlePacket(con, msg, m_PacketHandlers);
 }
Esempio n. 18
0
 /// <summary>
 /// Gets called when a game packet is about to be processed.  Return false to not process it.
 /// </summary>
 /// <param name="user"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 protected virtual bool OnBeforeHandleGamePacket(ServerUser user, PacketGameMessage msg)
 {
     return(true);
 }
Esempio n. 19
0
 protected override bool OnBeforeHandleGamePacket(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         return IsPlayerPartOfGame(user.CurrentCharacter.ID);
     }
     catch
     {
         return false;
     }
 }
Esempio n. 20
0
 /// <summary>
 /// While the game is in the lobby, you may request a new seat/team/etc.  The exact seat/team designation depends on the type of game being played.
 /// </summary>
 /// <param name="props">the requested setup arrangement</param>
 public void RequestNewSeating(PropertyBag props)
 {
     PacketGameMessage seat = new PacketGameMessage();
     seat.PacketSubTypeID = (int)LobbyGameMessageSubType.SeatChangeRequest;
     seat.Parms = props;
     Connection.Send(seat);
 }
Esempio n. 21
0
 private void OnPlayerDone(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         PlayerDone(user.CurrentCharacter);
     }
     catch
     {
     }
 }
Esempio n. 22
0
        /// <summary>
        /// Sends a PacketGameMessage to the game server for this particular game.  All PacketGameMessages are handled serially on the server in the
        /// order that they were received. 
        /// </summary>
        /// <param name="gamePacketSubType">packet type ID</param>
        /// <param name="parms">any paramters</param>
        public void SendGameMessage(int gamePacketSubType, PropertyBag parms = null)
        {
            if (!Client.GameServerReadyForPlay)
            {
                Log.LogMsg("Tried to send PacketGameMessage type [ " + gamePacketSubType.ToString() + "], but game server not ready.");
                return;
            }

            PacketGameMessage gm = new PacketGameMessage();
            gm.PacketSubTypeID = gamePacketSubType;
            gm.Parms = parms;
            Connection.Send(gm);
        }