예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #5
0
 private void OnPlayerDone(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         PlayerDone(user.CurrentCharacter);
     }
     catch
     {
     }
 }
예제 #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);
        }
예제 #7
0
 protected override bool OnBeforeHandleGamePacket(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         return(IsPlayerPartOfGame(user.CurrentCharacter.ID));
     }
     catch
     {
         return(false);
     }
 }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #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;
            }
        }
예제 #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
            }
        }
예제 #14
0
파일: ClientGame.cs 프로젝트: kamilion/WISP
        /// <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);
        }
예제 #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);
 }
예제 #16
0
 protected virtual void OnPlayerSeatChangeRequest(ServerUser fromPlayer, PacketGameMessage msg)
 {
 }
예제 #17
0
파일: ClientGame.cs 프로젝트: kamilion/WISP
 /// <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);
 }
예제 #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);
 }
예제 #19
0
 protected override bool OnBeforeHandleGamePacket(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         return IsPlayerPartOfGame(user.CurrentCharacter.ID);
     }
     catch
     {
         return false;
     }
 }
예제 #20
0
파일: ClientGame.cs 프로젝트: kamilion/WISP
 /// <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);
 }
예제 #21
0
 private void OnPlayerDone(ServerUser user, PacketGameMessage msg)
 {
     try
     {
         PlayerDone(user.CurrentCharacter);
     }
     catch
     {
     }
 }
예제 #22
0
파일: ClientGame.cs 프로젝트: kamilion/WISP
        /// <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);
        }