Beispiel #1
0
        /*
         * Packet flow
         *
         * 0001. S => C : unk
         * 0002. C => S : RSA Encrypted chunk (Salsa20 Key encrypted with RSA)
         * 0003. C => S : Password (1st packet)
         * 0004. C => S : Ping Packet (encrypted Salsa20)
         *
         */
        static void Main(string[] args)
        {
            PacketProcessor.TRSAInit();
            AsyncServer server = new AsyncServer(IPAddress.Parse("0.0.0.0"), 7979);
            server.Start();

            server.ConnectionAccepted += new AsyncServer.ConnectionAcceptedHandler(connection =>
            {
                Console.WriteLine("New connection: " + connection.GetHashCode());
                // Create AsyncState object
                connection.AsyncState = new AsyncConnectionData();
                // Send Packet 0001

                connection.DataReceived += new AsyncConnection.ConnectionDataReceivedHandler(data =>
                {
                    PacketProcessor.ProcessPacket(data, connection);
                });

                connection.SendClear(new byte[] {
                    0x03, 0x16, 0x00, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x36, 0x40, 0xce, 0x72, 0x71, 0xfe, 0x8d, 0x7e
                });
                // State is 1
                connection.SetState(1);

                connection.EngageReading();
            });

            Console.WriteLine("Server running, press Enter to exit ...");
            Console.ReadLine();
        }
Beispiel #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();
        }