/// <summary>
        /// Finds and creates packetlib for specified raw version.
        /// </summary>
        /// <param name="rawVersion">The version number sent by the client.</param>
        /// <param name="client">The client for which to create packet lib.</param>
        /// <param name="version">The client version of packetlib.</param>
        /// <returns>null if not found or new packetlib instance.</returns>
        public static IPacketLib CreatePacketLibForVersion(int rawVersion, GameClient client, out GameClient.eClientVersion version)
        {
            foreach (Type t in ScriptMgr.GetDerivedClasses(typeof(IPacketLib)))
            {
                foreach (PacketLibAttribute attr in t.GetCustomAttributes(typeof(PacketLibAttribute), false))
                {
                    if (attr.RawVersion == rawVersion)
                    {
                        try
                        {
                            IPacketLib lib = (IPacketLib)Activator.CreateInstance(t, new object[] { client });
                            version = attr.ClientVersion;
                            return(lib);
                        }
                        catch (Exception e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("error creating packetlib (" + t.FullName + ") for raw version " + rawVersion, e);
                            }
                        }
                    }
                }
            }

            version = GameClient.eClientVersion.VersionUnknown;
            return(null);
        }
Example #2
0
        public override void OnRecvPacket(GSPacketIn pkg)
        {
            if (this.m_packetProcessor == null)
            {
                this.m_packetLib       = AbstractPacketLib.CreatePacketLibForVersion(1, this);
                this.m_packetProcessor = new PacketProcessor(this);
            }
            if (this.m_player != null)
            {
                pkg.ClientID = this.m_player.PlayerId;
                pkg.WriteHeader();
            }
            pkg.ClearChecksum();
            switch (pkg.Code)
            {
            case 254:
                this.HandleManagerCmd(pkg);
                break;

            case 255:
                this.HandleManagerLogin(pkg);
                break;

            default:
                this.m_packetProcessor.HandlePacket(pkg);
                break;
            }
        }
Example #3
0
 public override void OnRecvPacket(GSPacketIn pkg)
 {
     if (this.m_packetProcessor == null)
     {
         this.m_packetLib       = AbstractPacketLib.CreatePacketLibForVersion(1, this);
         this.m_packetProcessor = new PacketProcessor(this);
     }
     if (this.m_player != null)
     {
         pkg.ClientID = this.m_player.PlayerId;
         pkg.WriteHeader();
     }
     this.m_packetProcessor.HandlePacket(pkg);
 }
Example #4
0
 /// <summary>
 /// 收到协议包
 /// </summary>
 /// <param name="pkg"></param>
 public override void OnRecvPacket(GSPacketIn pkg)
 {
     if (m_packetProcessor == null)
     {
         m_packetLib       = AbstractPacketLib.CreatePacketLibForVersion(1, this);
         m_packetProcessor = new PacketProcessor(this);
     }
     if (m_player != null)
     {
         pkg.ClientID = m_player.PlayerId;
         pkg.WriteHeader();
     }
     //LogMsg(Marshal.ToHexDump("recevie:", pkg.Buffer, 0, pkg.Length));
     m_packetProcessor.HandlePacket(pkg);
 }
Example #5
0
 /// <summary>
 /// 收到协议包
 /// </summary>
 /// <param name="pkg"></param>
 public override void OnRecvPacket(GSPacketIn pkg)
 {
     if (m_packetProcessor == null)
     {
         m_packetLib = AbstractPacketLib.CreatePacketLibForVersion(1, this);
         m_packetProcessor = new PacketProcessor(this);
     }
     if (m_player != null)
     {
         pkg.ClientID = m_player.PlayerId;
         pkg.WriteHeader();
     }
     //LogMsg(Marshal.ToHexDump("recevie:", pkg.Buffer, 0, pkg.Length));
     m_packetProcessor.HandlePacket(pkg);
 }
Example #6
0
        /// <summary>
        /// Called when a packet has been received.
        /// </summary>
        /// <param name="numBytes">The number of bytes received</param>
        /// <remarks>This function parses the incoming data into individual packets and then calls the appropriate handler.</remarks>
        protected override void OnReceive(int numBytes)
        {
            //This is the first received packet ...
            if (Version == eClientVersion.VersionNotChecked)
            {
                //Disconnect if the packet seems wrong
                if (numBytes < 17)                 // 17 is correct bytes count for 0xF4 packet
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("Disconnected {0} in login phase because wrong packet size {1}", TcpEndpoint, numBytes);
                        log.Warn("numBytes=" + numBytes);
                        log.Warn(Marshal.ToHexDump("packet buffer:", _pBuf, 0, numBytes));
                    }
                    GameServer.Instance.Disconnect(this);
                    return;
                }

                int version;

                /// <summary>
                /// The First Packet Format Change after 1.115c
                /// If "numbytes" is below 19 we have a pre-1.115c packet !
                /// </summary>
                if (numBytes < 19)
                {
                    //Currently, the version is sent with the first packet, no
                    //matter what packet code it is
                    version = (_pBuf[12] * 100) + (_pBuf[13] * 10) + _pBuf[14];

                    // we force the versionning: 200 correspond to 1.100 (1100)
                    // thus we could handle logically packets with version number based on the client version
                    if (version >= 200)
                    {
                        version += 900;
                    }
                }
                else
                {
                    // post 1.115c
                    // first byte is major (1), second byte is minor (1), third byte is version (15)
                    // revision (c) is also coded in ascii after that, then a build number appear using two bytes (0x$$$$)
                    version = _pBuf[11] * 1000 + _pBuf[12] * 100 + _pBuf[13];
                }

                eClientVersion ver;
                IPacketLib     lib = AbstractPacketLib.CreatePacketLibForVersion(version, this, out ver);

                if (lib == null)
                {
                    Version = eClientVersion.VersionUnknown;
                    if (log.IsWarnEnabled)
                    {
                        log.Warn(TcpEndpointAddress + " client Version " + version + " not handled on this server!");
                    }
                    GameServer.Instance.Disconnect(this);
                }
                else
                {
                    log.Info("Incoming connection from " + TcpEndpointAddress + " using client version " + version);
                    Version         = ver;
                    Out             = lib;
                    PacketProcessor = new PacketProcessor(this);
                }
            }

            if (Version != eClientVersion.VersionUnknown)
            {
                m_packetProcessor.ReceiveBytes(numBytes);
            }
        }