Пример #1
0
        public static void SendPacket(this AsyncConnection con, IServerPacket pkt)
        {
            byte opcode   = OpcodeManager.Instance.GetOpcode(pkt.GetType().Name);
            uint packetid = OpcodeManager.Instance.GetPacketID(pkt.GetType().Name);

            if (packetid == 0)
            {
                TORLog.Error("ERROR: No PacketID defined for " + pkt.GetType().Name);
                return;
            }
            ByteBuffer packet = new ByteBuffer(ByteOrder.LittleEndian);

            packet.WriteByte(opcode);
            packet.WriteInt(0);  // Length
            packet.WriteByte(0); // ChkByte
            packet.WriteUInt(packetid);
            pkt.WritePacket(con, packet);
            con.SendTORPacket(packet);
            TORLog.Network("PktSend @ " + con.GetHashCode() + " >> " + pkt.GetType().Name);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.Title = "Nexus Shard Server";

            Console.WriteLine("Nexus Shard Server\n");
            Utility.WriteLegal();
            Console.WriteLine("");

            AsyncServer server = new AsyncServer(IPAddress.Parse("0.0.0.0"), 20063);

            server.Start();

            server.ConnectionAccepted += new AsyncServer.ConnectionAcceptedHandler(connection =>
            {
                TORLog.Network("CnxAccept => " + connection.GetHashCode());
                connection.DataReceived += new AsyncConnection.ConnectionDataReceivedHandler(data =>
                {
                    if (connection.State == 1)
                    {
                        // rsa packet
                        connection.SetState(2);
                        connection.SendPacket(new SMsg_ClientSignatureRequest("OmegaServerProxyObjectName", 0x0174F5));
                        return;
                    }

                    ByteBuffer buffer = new ByteBuffer(ByteOrder.LittleEndian, data);
                    byte opcode       = (byte)buffer.ReadByte();

                    byte[] len_data = buffer.ReadBytes(4);
                    byte chk        = (byte)buffer.ReadByte();
                    uint packetid   = buffer.ReadUInt();

                    if (chk != (byte)(opcode ^ len_data[0] ^ len_data[1] ^ len_data[2] ^ len_data[3]))
                    {
                        TORLog.Warn("Received packet with invalid checksum!");
                    }

                    if (opcode == 1) // Client Ping Packet
                    {
                        TORLog.Network("Ping from " + connection.GetHashCode() + " Seq = " + packetid);
                        ByteBuffer response = new ByteBuffer(ByteOrder.LittleEndian);
                        response.WriteByte(2);        // Pong OPC = 2
                        response.WriteInt(0);         // Pong Len
                        response.WriteByte(0);        // Pong Chk
                        response.WriteUInt(packetid); // Pong
                        response.WriteInt(0);
                        response.WriteInt(1);
                        response.WriteByte(0);
                        connection.SendTORPacket(response);
                        return;
                    }

                    string packetname = OpcodeManager.Instance.GetPacketName(opcode, packetid);

                    if (packetname == "")
                    {
                        TORLog.Warn("Received unknown packet from SWTOR client\nOpcode = 0x" + opcode.ToString("X2") + " -- PacketID = 0x" + packetid.ToString("X8"));
                        TORLog.Warn("--- dump ---");
                        TORLog.Warn(Utility.HexDump(data));
                    }
                    else
                    {
                        try
                        {
                            IClientPacket pkt = Activator.CreateInstance(Type.GetType("ShardServer.Packets.Client." + packetname)) as IClientPacket;
                            TORLog.Network("PktRecv @ " + connection.GetHashCode() + " << " + packetname);
                            pkt.ExecutePacket(connection, buffer);
                        }
                        catch (Exception ex)
                        {
                            TORLog.Error("Exception occured while processing " + packetname, ex);
                        }
                    }
                });
                // Send HELLO packet
                connection.SendClear(new byte[] { 0x03, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
                // State is 1
                connection.SetState(1);
                connection.EngageReading();
            });

            TORLog.Info("SHARD Server running, press Enter to exit ...");
            Console.ReadLine();
        }