Ejemplo n.º 1
0
        public override bool OnBeforePacketProcessed(Packet p)
        {
            // if the base class doesn't think we should process the packet, then we don't think so either.
            if (!base.OnBeforePacketProcessed(p)) // check for duplicate requests and send ACK if requested
            {
                return(false);
            }

            // Check for authorization.  The only packet types that do not require authorization are ServerGreeting, RijndaelExchange, LineSecured, LoginRequest/Result, Null and Reply
            // these are defined as -1000 to -994.
            if (p.PacketTypeID < -1000 || p.PacketTypeID > -994 && !ServerUser.IsAuthorizedClusterServer)
            {
                if (ServerUser.AuthorizationExpires < DateTime.UtcNow)
                {
                    PacketReply rep = CreateStandardReply(p, ReplyType.AuthorizationTicketExpired, "Not authorized.");
                    p.NeedsReply  = true;
                    p.ReplyPacket = rep;
                    Send(rep);
                    KillConnection("Authorization expired.");
                    return(false); // prevent calling handler for this packet, since we're not authorized
                }
                else
                {
                    ServerUser.RenewAuthorizationTicket();
                }
            }

            if (p.PacketTypeID != (int)PacketType.ACK && p.PacketTypeID != (int)PacketType.NATInfo)
            {
                m_TimeoutTimer.Stop();
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void OnCharacterCreateRequest(INetworkConnection con, Packet gmsg)
        {
            PacketGenericMessage msg = gmsg as PacketGenericMessage;
            string rsltMsg           = "";
            ServerCharacterInfo ci   = null;

            if (MyServer.UseCharacters)
            {
                ci = CharacterUtil.Instance.CreateNewCharacter(msg.Parms, ServerUser);
            }

            ReplyType rslt = ReplyType.Failure;

            if (ci != null && OnValidateCharacterCreateRequest(ci, ref rsltMsg))
            {
                if (CharacterUtil.Instance.PersistNewCharacter(ci, ServerUser, ref rsltMsg, !MyServer.RequireAuthentication))
                {
                    rslt = ReplyType.OK;
                }
            }

            PacketReply rep = CreateStandardReply(msg, rslt, rsltMsg);

            msg.ReplyPacket = rep;
        }
Ejemplo n.º 3
0
        protected void OnGameStartReply(INetworkConnection con, Packet p)
        {
            PacketReply rep = p as PacketReply;

            if (rep.ReplyCode != ReplyType.OK)
            {
                // only fire this event if it the request fails.
                // if the start request succeeds, then OnGameStarted will fire
                FireGameStartReply(this, false, rep.ReplyMessage);
            }
        }
Ejemplo n.º 4
0
        private void OnConfigRequest(INetworkConnection con, Packet r)
        {
            Log1.Logger("Zeus").Debug("Config listing request from " + ServerUser.AccountName + ".");

            WispConfigSettings cfg = new WispConfigSettings();

            cfg.Configs = MyServer.AppConfig;
            PacketReply rep = CreateStandardReply(r, ReplyType.OK, "");

            rep.Parms.SetProperty(1, cfg);
            r.ReplyPacket = rep;
        }
Ejemplo n.º 5
0
        protected void SendGameMessageReply(ServerUser client, ReplyType rp, string msg, Packet inResponseToPacket, PropertyBag parms, bool compress, bool encrypt)
        {
            PacketReply rmsg = client.MyConnection.CreateStandardReply(inResponseToPacket, rp, msg);

            if (parms != null)
            {
                rmsg.Parms = parms;
            }
            rmsg.IsCompressed = compress;
            rmsg.IsEncrypted  = encrypt;
            inResponseToPacket.ReplyPacket = rmsg;
        }
Ejemplo n.º 6
0
        protected virtual void OnRequestDeleteCharacterReply(INetworkConnection con, Packet reply)
        {
            PacketReply p = reply as PacketReply;

            if (p.ReplyCode != ReplyType.OK)
            {
                FireDeleteCharacterFailed(p.ReplyMessage);
            }
            else
            {
                RequestCharacterListing();
            }
        }
Ejemplo n.º 7
0
        protected virtual void OnRequestSelectCharacterReply(INetworkConnection con, Packet reply)
        {
            PacketReply p = reply as PacketReply;

            if (p.ReplyCode != ReplyType.OK)
            {
                FireSelectCharacterFailed(p.ReplyMessage);
            }
            else if (p.ReplyCode == ReplyType.OK)
            {
                CurrentCharacter = p.Parms.GetComponentProperty((int)PropertyID.CharacterInfo) as CharacterInfo;
                FireCharacterActivated(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 8
0
        private void OnCharacterDeleteRequest(INetworkConnection con, Packet gmsg)
        {
            PacketGenericMessage msg = gmsg as PacketGenericMessage;
            string    rsltMsg        = "";
            ReplyType rslt           = ReplyType.Failure;
            int       characterId    = msg.Parms.GetIntProperty((int)PropertyID.CharacterId).GetValueOrDefault();

            if (MyServer.UseCharacters && MyServer.RequireAuthentication && CharacterUtil.Instance.DeleteCharacter(characterId, ServerUser, false, "Player requested deletion from [" + con.RemoteEndPoint.ToString() + "].", ref rsltMsg))
            {
                rslt = ReplyType.OK;
            }

            PacketReply rep = CreateStandardReply(msg, rslt, rsltMsg);

            msg.ReplyPacket = rep;
        }
Ejemplo n.º 9
0
        private void HandlePacket(LobbyClientGameServerOutboundConnection con, PacketReply msg, PacketHandlerMap map)
        {
            Action <INetworkConnection, Packet> handler = map.GetHandlerDelegate(msg.PacketSubTypeID);

            if (handler != null)
            {
                try
                {
                    handler(con, 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() + ". ");
        }
Ejemplo n.º 10
0
        private void OnCharacterSelectRequest(INetworkConnection con, Packet mesg)
        {
            PacketGenericMessage genMsg = mesg as PacketGenericMessage;
            string              msg     = "";
            ReplyType           rslt    = ReplyType.OK;
            int                 id      = genMsg.Parms.GetIntProperty((int)PropertyID.CharacterId).GetValueOrDefault(-1);
            ServerCharacterInfo ci      = null;

            // if we don't use characters, there wont be one in the DB
            if (MyServer.UseCharacters)
            {
                ci = CharacterUtil.Instance.LoadCharacter(ServerUser, id, ref msg);
            }

            if (ci == null && ServerUser.CurrentCharacter != null && ServerUser.CurrentCharacter.ID == id)
            {
                ci = ServerUser.CurrentCharacter;
            }

            PacketReply rep = CreateStandardReply(genMsg, rslt, msg);

            //genMsg.ReplyPacket = rep;

            if (ci == null)
            {
                genMsg.ReplyPacket = rep;
                rep.ReplyCode      = ReplyType.Failure;
                rep.ReplyMessage   = "Unable to load character.";
                return;
            }

            ServerUser.CurrentCharacter = ci;
            CharacterCache.CacheCharacter(ci, MyServer.ServerUserID, TimeSpan.MaxValue);

            rep.Parms.SetProperty((int)PropertyID.CharacterInfo, ci.CharacterInfo as IComponent);

            Send(rep); // reply needs to arrive before the OnSelected event is fired, in case OnSelected results in a server transfer
            OnCharacterSelected(ci);
        }
Ejemplo n.º 11
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 HandleGamePacketReply(LobbyClientGameServerOutboundConnection con, PacketReply msg)
 {
     HandlePacket(con, msg, m_GameReplyHandlerMap);
 }
Ejemplo n.º 12
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 HandleGamePacketReply(LobbyClientGameServerOutboundConnection con, PacketReply msg)
 {
     HandlePacket(con, msg, m_GameReplyHandlerMap);
 }
Ejemplo n.º 13
0
        private void HandlePacket(LobbyClientGameServerOutboundConnection con, PacketReply msg, PacketHandlerMap map)
        {
            Action<INetworkConnection, Packet> handler = map.GetHandlerDelegate(msg.PacketSubTypeID);
            if (handler != null)
            {
                try
                {
                    handler(con, 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() + ". ");
        }
Ejemplo n.º 14
0
 protected virtual void OnPacketAuthFailed(PacketReply replyPacket)
 {
 }