Пример #1
0
        public static Tuple <byte[], int, int> _7LoginMessages(BinaryReader data, int TCPPort, int UDPPort, string Key)
        {
            uint msgid  = DataHandler.MSGID(data);
            uint msglen = DataHandler.USHRT(data);


            if (msgid == 1)
            {
                Console.WriteLine("MSG_CHARACTERINFO");
            }
            else if (msgid == 2)
            {
                Console.WriteLine("MSG_CHARACTERLIST");
            }
            else if (msgid == 3)
            {
                Console.WriteLine("MSG_CHARACTERSELECTED");
            }
            else if (msgid == 4)
            {
                Console.WriteLine("MSG_CREATECHARACTER");
            }
            else if (msgid == 5)
            {
                Console.WriteLine("MSG_CREATECHARACTERRESPONSE");
            }
            else if (msgid == 6)
            {
                Console.WriteLine("MSG_DELETECHARACTER");
            }
            else if (msgid == 7)
            {
                Console.WriteLine("MSG_DELETECHARACTERRESPONSE");
            }
            else if (msgid == 8)
            {
                Console.WriteLine("MSG_REQUESTCHARACTERLIST");
                //Return the characterlist
                //This is just a debug charlist ripped straight from a packet capture.
                //It includes more than one packet (startcharlist, char, char, char, char, endcharlist)

                KIPacket TempResponse = new KIPacket(); //Init a new packet
                TempResponse.Header(0, 0, 7, 12);       //Set header to svcid:7, msgid:12 (MSG_STARTCHARACTERLIST)
                TempResponse._STR("WizPS.Login");       //LoginServer string (not important, just used for window title)
                TempResponse._INT(0);                   //Purchased character slots (0 character slots purchased)
                byte[] PKT1 = TempResponse.Finalise();  //Save KIPacket as the first packet to send


                TempResponse = new KIPacket();   //Reset the KIPacket (resets length counters)
                TempResponse.Header(0, 0, 7, 1); //MSG_CHARACTERINFO (character 1)
                TempResponse._HEXSTRING("82 00 4C 8F 6E 11 01 00 00 00 00 00 00 E9 30 20 01 00 00 AB 02 D0 DF 33 07 E8 03 00 00 00 07 8D D0 72 24 80 C0 58 20 81 80 40 01 00 00 00 88 BE C1 04 00 00 00 00 00 00 C3 CA F5 40 03 00 00 00 44 64 73 43 84 12 00 00 00 00 00 00 00 00 00 00 00 00 44 64 73 43 C4 EF 01 00 00 00 00 00 00 00 00 00 00 00 44 64 73 43 4B 54 01 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 49 1C 01 00 30 33 0B 00");
                byte[] PKT2 = TempResponse.Finalise();


                TempResponse = new KIPacket();
                TempResponse.Header(0, 0, 7, 1); //MSG_CHARACTERINFO (character 2)
                TempResponse._HEXSTRING("85 00 4C 8F 6E 11 01 00 00 00 00 00 00 F1 30 20 01 00 00 AB 02 D0 DF 33 07 E8 03 00 00 00 07 8D D0 72 14 00 80 4C 0C 31 80 18 01 00 00 00 88 BE C1 04 00 00 00 00 00 00 C3 CA F5 40 02 00 00 00 44 64 73 43 84 12 00 00 00 00 00 00 00 00 00 00 00 00 44 64 73 43 C3 EF 01 00 00 00 00 00 00 00 00 00 00 00 15 00 57 69 7A 61 72 64 5A 6F 6E 65 5F 54 68 65 43 6F 6D 6D 6F 6E 73 02 00 00 00 06 C1 23 00 0B 1A 4D 00");
                byte[] PKT3 = TempResponse.Finalise();


                TempResponse = new KIPacket();
                TempResponse.Header(0, 0, 7, 1); //MSG_CHARACTERINFO (character 3)
                TempResponse._HEXSTRING("A8 00 4C 8F 6E 11 01 00 00 00 00 00 00 A9 81 22 01 00 00 AA 02 D0 DF 33 07 E8 03 00 00 00 07 8D D0 72 38 00 80 2D 80 00 40 00 01 00 00 00 88 BE C1 04 00 00 00 02 00 00 C3 CA F5 40 04 00 00 00 44 64 73 43 84 12 00 00 00 00 00 00 00 00 00 00 00 00 44 64 73 43 C6 EF 01 00 00 00 00 00 00 00 00 00 00 00 44 64 73 43 F1 2E 01 00 61 00 00 00 00 00 00 00 00 00 44 64 73 43 CC 12 00 00 61 00 00 00 00 00 00 00 00 00 14 00 57 69 7A 61 72 64 5A 6F 6E 65 5F 52 61 76 65 6E 77 6F 6F 64 04 00 00 00 0D 5B 25 00 20 3F 3F 00");
                byte[] PKT4 = TempResponse.Finalise();

                TempResponse = new KIPacket();
                TempResponse.Header(0, 0, 7, 2); //MSG_CHARACTERLIST (signifies the end of a character list)
                TempResponse._UINT(0);           //Error (0 means no error)
                byte[] PKT5 = TempResponse.Finalise();


                //byte [] response = PKT1.Concat(PKT2).ToArray().Concat(PKT3).ToArray().Concat(PKT4).ToArray().Concat(PKT5).ToArray(); //Combine all of the packets into one single packet (the game accepts multile packets concated into one)
                byte[] response = PKT1.Concat(PKT4).ToArray().Concat(PKT5).ToArray();
                Console.WriteLine("CHARACTER LIST SENT!");
                return(Tuple.Create(response, 0, 0));
            }
            else if (msgid == 9)
            {
                Console.WriteLine("MSG_REQUESTSERVERLIST");
            }
            else if (msgid == 10)
            {
                Console.WriteLine("MSG_SELECTCHARACTER");


                //Craft packet to inform client that the server is processing the request (make the game show the 'verifying character' dialogue)

                KIPacket TempResponse = new KIPacket();      //Initialise new packet
                TempResponse.Header(0x00, 0x00, 0x07, 0x03); //Create header with SVCID 7 and MSGID 3 (MSG_CHARACTERSELECTED)
                TempResponse._STR("");                       //IP
                TempResponse._INT(0);                        //TCPPORT
                TempResponse._INT(0);                        //UDPPORT
                TempResponse._STR("");                       //KEY
                TempResponse._GID(0);                        //UserID
                TempResponse._GID(0);                        //CharID
                TempResponse._GID(0);                        //ZoneID
                TempResponse._STR("");                       //ZoneName
                TempResponse._STR("");                       //Location
                TempResponse._INT(0);                        //Slot
                TempResponse._INT(1);                        //PrepPhase
                TempResponse._INT(0);                        //Error
                TempResponse._STR("WizPS.Login");            //LoginServer
                byte[] packet1 = TempResponse.Finalise();

                return(Tuple.Create(packet1, 1, 0)); //Return temporary packet, informing the client that the server is processing the transfer. Return 1, so that the caller knows to initiate a transfer
                //After this, the login server will be neglected. So switch all data to the gameserver now

                /*
                 * Message structure:
                 * <IP TYPE="STR"></IP>
                 * <TCPPort TYPE="INT"></TCPPort>
                 * <UDPPort TYPE="INT"></UDPPort>
                 * <Key TYPE="STR"></Key>
                 * <UserID TYPE="GID"></UserID>
                 * <CharID TYPE="GID"></CharID>
                 * <ZoneID TYPE="GID"></ZoneID>
                 * <ZoneName TYPE="STR"></ZoneName>
                 * <Location TYPE="STR"></Location>
                 * <Slot TYPE="INT"></Slot>
                 * <PrepPhase TYPE="INT"></PrepPhase>
                 * <Error TYPE="INT"></Error>
                 * <LoginServer TYPE="STR"></LoginServer>
                 */
            }
            else if (msgid == 11)
            {
                Console.WriteLine("MSG_SERVERLIST");
            }
            else if (msgid == 12)
            {
                Console.WriteLine("MSG_STARTCHARACTERLIST");
            }
            else if (msgid == 13)
            {
                Console.WriteLine("MSG_USER_AUTHEN");
            }
            else if (msgid == 14)
            {
                Console.WriteLine("MSG_USER_AUTHEN_RSP");
            }
            else if (msgid == 15)
            {
                Console.WriteLine("MSG_USER_VALIDATE");
                UInt64 UserID        = DataHandler.GID(data);
                string PassKey3      = DataHandler.STR(data);
                UInt64 MachineID     = DataHandler.GID(data);
                string Locale        = DataHandler.STR(data);
                string PatchClientID = DataHandler.STR(data);

                Console.WriteLine("User ID: {0}", UserID);
                Console.WriteLine("PassKey3: {0}", PassKey3);
                Console.WriteLine("Machine ID: {0}", MachineID);
                Console.WriteLine("Locale: {0}", Locale);
                Console.WriteLine("Patch Client ID: {0}", PatchClientID);

                byte[] response1 = { 0x0d, 0xf0, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x10, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0xdf, 0x33, 0x07, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //MSG_USER_VALIDATE_RSP, informs the client that they have authenticated successfully (for debug purposes, will always admit the user. For an actual server, client keys will be verified.)
                byte[] response2 = { 0x0d, 0xf0, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x14, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };                                                                                                 //MSG_USER_ADMIT_IND, informs the client that they can join the game (allows them to click the 'play' button from the character-select screen)
                byte[] response  = response1.Concat(response2).ToArray();
                return(Tuple.Create(response, 0, 0));
            }
            else if (msgid == 16)
            {
                Console.WriteLine("MSG_USER_VALIDATE_RSP");
            }
            else if (msgid == 17)
            {
                Console.WriteLine("MSG_DISCONNECT_LOGIN_AFK");
            }
            else if (msgid == 18)
            {
                Console.WriteLine("MSG_LOGIN_NOT_AFK");
            }
            else if (msgid == 19)
            {
                Console.WriteLine("MSG_LOGINSERVERSHUTDOWN");
            }
            else if (msgid == 20)
            {
                Console.WriteLine("MSG_USER_ADMIT_IND");
            }
            else if (msgid == 21)
            {
                Console.WriteLine("MSG_WEBCHARACTERINFO");
            }
            else if (msgid == 22)
            {
                Console.WriteLine("MSG_USER_AUTHEN_V2");
            }
            else if (msgid == 23)
            {
                Console.WriteLine("MSG_SAVECHARACTER");
            }
            else if (msgid == 24)
            {
                Console.WriteLine("MSG_WEB_AUTHEN");
            }
            else if (msgid == 25)
            {
                Console.WriteLine("MSG_WEB_VALIDATE");
            }
            else if (msgid == 26)
            {
                Console.WriteLine("MSG_CHANGECHARACTERNAME");
            }
            else if (msgid == 27)
            {
                Console.WriteLine("MSG_USER_AUTHEN_V3");
            }
            else
            {
                Console.WriteLine("UNSUPPORTED MESSAGE! Make sure you are running revision r667549.Wizard_1_390");
            }

            return(null);
        }
Пример #2
0
        public static async Task GS()
        {
            Console.WriteLine("GAME SERVER STARTED!");
            TcpListener server = null;

            try
            {
                //Start a new server with the gameserver's ip/port
                server = new TcpListener(GS_Settings.IP, GS_Settings.TCPPort);

                //Start listening for client requests.
                server.Start();

                //Buffer for reading data. 4096 bytes should be fine
                Byte[] bytes = new Byte[4096];

                //Enter the listening loop.
                while (true)
                {
                    Console.Write("GS: Waiting for a connection...\n");
                    GS_Settings.SocketOpen  = false;
                    GS_Settings.SessionOpen = false;

                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("GS: Connected!\n");

                    //Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    Console.WriteLine("GS: AWAITING MESSAGE");

                    int i;

                    try
                    {
                        if (!GS_Settings.SocketOpen)
                        {
                            stream.ReadTimeout = 300; //300 ms timeout if the session isn't open
                        }
                        else
                        {
                            stream.ReadTimeout = 100000; //Timeout of 100000ms if the session is open
                        }
                        while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                        {
                            if (!GS_Settings.SocketOpen)             //If a socket hasn't been opened
                            {
                                Program.Globals.SessionOpen = false; //Inform the rest of the program that a new session needs to be made
                                Program.Globals.Sessid      = 0792;  //0318
                            }
                            GS_Settings.SocketOpen = true;           //Let the program know that the socket is open (so don't timeout anymore)
                            stream.ReadTimeout     = 100000;
                            try
                            {
                                Tuple <byte[], int, int> temptuple = MessageParser.Parse(bytes, GS_Settings.TCPPort, GS_Settings.UDPPort, GS_Settings.Key, GS_Settings.SessionOpen, GS_Settings.SessionID);
                                if (temptuple == null)
                                {
                                    continue;
                                }
                                byte[] response     = temptuple.Item1;
                                int    requestlogin = temptuple.Item2;
                                int    SessionOpen  = temptuple.Item3;
                                if (response != null)
                                {
                                    stream.Write(response, 0, response.Length);
                                    if (requestlogin == 1)
                                    {
                                        KIPacket RealResponse = new KIPacket();       //Initialise new packet
                                        RealResponse.Header(0x00, 0x00, 0x07, 0x03);  //Create header with SVCID 7 and MSGID 3 (MSG_CHARACTERSELECTED)
                                        RealResponse._STR("127.0.0.1");               //IP
                                        RealResponse._INT(GS_Settings.TCPPort);       //TCPPORT
                                        RealResponse._INT(GS_Settings.UDPPort);       //UDPPORT
                                        RealResponse._STR(GS_Settings.Key);           //KEY
                                        RealResponse._GID(4295088136144);             //UserID
                                        RealResponse._GID(191965934135706025);        //CharID
                                        RealResponse._GID(123004564835992122);        //ZoneID
                                        RealResponse._STR("WizardCity/WC_Ravenwood"); //ZoneName
                                        RealResponse._STR("2572,4376,-28,5.55");      //Location
                                        RealResponse._INT(0);                         //Slot
                                        RealResponse._INT(0);                         //PrepPhase
                                        RealResponse._INT(0);                         //Error
                                        RealResponse._STR("WizPS.Login");             //LoginServer (Not important, just displayed in title bar)
                                        byte[] packet2 = RealResponse.Finalise();
                                        stream.Write(packet2, 0, packet2.Length);
                                    }
                                    if (SessionOpen == 1)
                                    {
                                        GS_Settings.SessionOpen = true;
                                    }
                                }
                            }
                            catch //If the data couldn't be parsed, print the data packet
                            {
                                string data = null;

                                for (int q = 0; q < bytes.Length; q++)
                                {
                                    data = data + bytes[q].ToString("X2");
                                }
                                Console.WriteLine("GS: Received: {0}\n", data);
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("GS: NO DATA RECEIVED!\n");
                    }
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Login: SocketException: {0}\n", e);
            }
            finally
            {
                // Stop listening for new clients.
                Console.WriteLine("\n\n\n====================\nGS: SERVER STOP\n====================\n\n\n");
                server.Stop();
            }


            Console.WriteLine("\nHit enter to continue...");
            Console.Read();

            //login.us.wizard101.com (165.193.63.4)
            //login server sends/receives on port 12000. Client changes ports randomly between range of 12000-12999
            return;
        }
Пример #3
0
        public static async Task LS()
        {
            TcpListener server = null;

            try
            {
                // TcpListener server = new TcpListener(port);
                server = new TcpListener(LS_Settings.IP, LS_Settings.TCPPort);

                // Start listening for client requests.
                server.Start();

                // Buffer for reading data. 4096 bytes should be fine
                Byte[] bytes = new Byte[4096];

                // Enter the listening loop.
                while (true)
                {
                    Console.Write("Login: Waiting for a connection...\n");
                    LS_Settings.SocketOpen  = false;
                    LS_Settings.SessionOpen = false;

                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("Login: Connected!\n");

                    // Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    Console.WriteLine("LOGIN: AWAITING MESSAGE");

                    int i;

                    try
                    {
                        if (!LS_Settings.SocketOpen)
                        {
                            stream.ReadTimeout = 300; //300 ms timeout if the session isn't open
                        }
                        else
                        {
                            stream.ReadTimeout = 100000; //Timeout of 100000ms if the session is open
                        }
                        while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                        {
                            LS_Settings.SocketOpen = true; //Let the program know that the socket is open (so don't timeout anymore)
                            stream.ReadTimeout     = 100000;
                            try
                            {
                                Tuple <byte[], int, int> temptuple = MessageParser.Parse(bytes, LS_Settings.TCPPort, LS_Settings.UDPPort, LS_Settings.Key, LS_Settings.SessionOpen, LS_Settings.SessionID);
                                if (temptuple == null)
                                {
                                    continue;
                                }
                                byte[] response     = temptuple.Item1;
                                int    requestlogin = temptuple.Item2;
                                int    SessionOpen  = temptuple.Item3;
                                if (response != null)
                                {
                                    stream.Write(response, 0, response.Length);
                                    if (requestlogin == 1)
                                    {
                                        KIPacket RealResponse = new KIPacket();       //Initialise new packet
                                        RealResponse.Header(0x00, 0x00, 0x07, 0x03);  //Create header with SVCID 7 and MSGID 3 (MSG_CHARACTERSELECTED)
                                        RealResponse._STR("127.0.0.1");               //IP
                                        RealResponse._INT(GS_Settings.TCPPort);       //TCPPORT
                                        RealResponse._INT(GS_Settings.UDPPort);       //UDPPORT
                                        RealResponse._STR(GS_Settings.Key);           //KEY
                                        RealResponse._GID(4295088136144);             //UserID
                                        RealResponse._GID(191965934135706025);        //CharID
                                        RealResponse._GID(123004564835992122);        //ZoneID
                                        RealResponse._STR("WizardCity/WC_Ravenwood"); //ZoneName
                                        RealResponse._STR("2572,4376,-28,5.55");      //Location (X,Y,Z,ROT)
                                        RealResponse._INT(0);                         //Slot
                                        RealResponse._INT(0);                         //PrepPhase
                                        RealResponse._INT(0);                         //Error
                                        RealResponse._STR("WizPS.Login");             //LoginServer
                                        byte[] packet2 = RealResponse.Finalise();
                                        stream.Write(packet2, 0, packet2.Length);
                                    }
                                    if (SessionOpen == 1)
                                    {
                                        LS_Settings.SessionOpen = true;
                                    }
                                }
                            }
                            catch //If the data couldn't be parsed, print the data packet
                            {
                                string data = null;

                                for (int q = 0; q < bytes.Length; q++)
                                {
                                    data = data + bytes[q].ToString("X2");
                                }
                                Console.WriteLine("Login: Received: {0}\n", data);
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Login: NO DATA RECEIVED!\n");
                    }
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Login: SocketException: {0}\n", e);
            }
            finally
            {
                // Stop listening for new clients.
                Console.WriteLine("\n\n\n====================\nLogin: SERVER STOP\n====================\n\n\n");
                server.Stop();
            }


            Console.WriteLine("\nHit enter to continue...");
            Console.Read();

            return;
        }
Пример #4
0
        public static async Task PS()
        {
            TcpListener server = null;

            try
            {
                // TcpListener server = new TcpListener(port);
                server = new TcpListener(PS_Settings.IP, PS_Settings.TCPPort);

                // Start listening for client requests.
                server.Start();

                // Buffer for reading data. 4096 bytes should be fine
                Byte[] bytes = new Byte[4096];
                String data  = null;

                // Enter the listening loop.
                while (true)
                {
                    Console.Write("Patch: Waiting for a connection...\n");
                    PS_Settings.SocketOpen  = false;
                    PS_Settings.SessionOpen = false;

                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("Patch: Connected!\n");

                    data = null;

                    // Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    int i;

                    // Loop to receive all the data sent by the client.
                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        try
                        {
                            Tuple <byte[], int, int> temptuple = MessageParser.Parse(bytes, PS_Settings.TCPPort, PS_Settings.UDPPort, PS_Settings.Key, PS_Settings.SessionOpen, PS_Settings.SessionID);
                            if (temptuple == null)
                            {
                                continue;
                            }
                            byte[] response     = temptuple.Item1;
                            int    requestlogin = temptuple.Item2;
                            int    SessionOpen  = temptuple.Item3;
                            if (response != null)
                            {
                                stream.Write(response, 0, response.Length);
                                if (requestlogin == 1)
                                {
                                    KIPacket RealResponse = new KIPacket();       //Initialise new packet
                                    RealResponse.Header(0x00, 0x00, 0x07, 0x03);  //Create header with SVCID 7 and MSGID 3 (MSG_CHARACTERSELECTED)
                                    RealResponse._STR("127.0.0.1");               //IP
                                    RealResponse._INT(PS_Settings.TCPPort);       //TCPPORT
                                    RealResponse._INT(PS_Settings.UDPPort);       //UDPPORT
                                    RealResponse._STR(PS_Settings.Key);           //KEY
                                    RealResponse._GID(4295088136144);             //UserID
                                    RealResponse._GID(191965934135706025);        //CharID
                                    RealResponse._GID(123004564835992122);        //ZoneID
                                    RealResponse._STR("WizardCity/WC_Ravenwood"); //ZoneName
                                    RealResponse._STR("2572,4376,-28,5.55");      //Location
                                    RealResponse._INT(0);                         //Slot
                                    RealResponse._INT(0);                         //PrepPhase
                                    RealResponse._INT(0);                         //Error
                                    RealResponse._STR("WizPS.Patch");             //LoginServer
                                    byte[] packet2 = RealResponse.Finalise();
                                    stream.Write(packet2, 0, packet2.Length);
                                }
                                if (SessionOpen == 1)
                                {
                                    PS_Settings.SessionOpen = true;
                                }
                            }
                        }
                        catch //If the data couldn't be parsed, write the data packet
                        {
                            for (int q = 0; q < bytes.Length; q++)
                            {
                                data = data + bytes[q].ToString("X2");
                            }
                            Console.WriteLine("Patch: Received: {0}\n", data);
                        }
                    }
                    Console.WriteLine("Patch: NO DATA RECEIVED!\n");
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Patch: SocketException: {0}\n", e);
            }
            finally
            {
                // Stop listening for new clients.
                Console.WriteLine("Patch: SERVER STOP\n");
                server.Stop();
            }


            Console.WriteLine("\nHit enter to continue...");
            Console.Read();
            return;
        }