//When a client disconnects
 public static void _OnClientDisconnect(object o)
 {
     //Set definition info
     Definitions.Clientdefinition c = (Definitions.Clientdefinition)o;
     //Close client socket
     c.client.clientSocket.Close();
 }
        public static void ClientCheck2(Definitions.Clientdefinition sys)
        {
            PacketWriter Writer = new PacketWriter();

            Writer.Create(0x2005);
            Writer.Byte(1);
            Writer.Byte(0);
            Writer.Byte(1);
            Writer.Byte(0x47);
            Writer.Byte(1);
            Writer.Byte(5);
            Writer.Byte(0);
            Writer.Byte(0);
            Writer.Byte(0);
            Writer.Byte(2);
            sys.client.Send(Writer.GetBytes());
            Writer = new PacketWriter();
            Writer.Create(0x6005);
            Writer.Byte(3);
            Writer.Byte(0);
            Writer.Byte(2);
            Writer.Byte(0);
            Writer.Byte(2);
            sys.client.Send(Writer.GetBytes());
            Writer = new PacketWriter();
            Writer.Create(0xA100);
            Writer.Byte(1);
            Writer.Byte(0);
            sys.client.Send(Writer.GetBytes());
        }
Exemplo n.º 3
0
        //Public void select opcode
        public static void Opcode_List(Decode information)

        {
            //Set definition for detailed information
            Definitions.Clientdefinition Control = (Definitions.Clientdefinition)information.Packet;
            //Set Packetinformation as information (short).
            Control.PacketInformation = information;
            //Create a new packet reader to view incoming packet data
            PacketReader R = new PacketReader(Control.PacketInformation.buffer);

            //Create switch code based on the opcode the client sends.
            switch (information.opcode)
            {
            case Opcodes.CLIENT.CLIENT_PING_CHECK:
                break;

            case Opcodes.CLIENT.CLIENT_INFO:
                //If the client connecting is silkroad
                if (R.Text() == "SR_Client")
                {
                    Control.client.Send(Connect.GateWayPacket());
                }
                break;

            case Opcodes.CLIENT.CLIENT_GATEWAY_PATCH_REQUEST:
                Functions.Connect.ClientCheck(Control);
                break;

            case Opcodes.CLIENT.CLIENT_GATEWAY_SERVERLIST_REQUEST:
                Control.client.Send(Serverlist.ServerListPacket(0));
                break;

            case Opcodes.CLIENT.CLIENT_GATEWAY_LOGIN_REQUEST:
                Functions.Auth.Connect(Control);
                break;

            case Opcodes.CLIENT.CLIENT_GATEWAY_NOTICE_REQUEST:
                Control.client.Send(Connect._6());
                Control.client.Send(News.NewsPacket());
                break;

            case 1905:
                byte[] buffer = information.buffer;
                Definitions.Clientdefinition.Connected_Users = BitConverter.ToInt16(buffer, 0);
                break;

            default:
                break;
            }
        }
        public static void ClientCheck(Definitions.Clientdefinition sys)
        {
            PacketReader Reader  = new PacketReader(sys.PacketInformation.buffer);
            byte         Locale  = Reader.Byte();
            string       Name    = Reader.Text();
            int          Version = Reader.Int32();

            Reader.Close();
            try
            {
                if (Name == "SR_Client")
                {
                    sys.client.Send(Core.Packets.Connect._1());
                    sys.client.Send(Core.Packets.Connect._2());
                    sys.client.Send(Core.Packets.Connect._3());
                    sys.client.Send(Core.Packets.Connect._4());
                    sys.client.Send(Core.Packets.Connect._5());
                    if (Version == Definitions.Serverdef.SilkroadClientVersion)//
                    {
                        sys.client.Send(Core.Packets.Connect.ActualVersion());
                    }
                    else if (Version < Definitions.Serverdef.SilkroadClientVersion - 1)//
                    {
                        sys.client.Send(Core.Packets.Connect.ClientIsToOld());
                    }
                    else if (Version > Definitions.Serverdef.SilkroadClientVersion)//
                    {
                        sys.client.Send(Core.Packets.Connect.ClientIsToNew());
                    }
                    else
                    {
                        //sys.client.Send(Patch.SendPatchFiles());
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("Connect.cs Error: {0}", error);
            }
        }
 //On client connect void
 public static void _OnClientConnect(ref object de, CLFramework.SRClient net)
 {
     de = new Definitions.Clientdefinition(net);
 }
 //On client connect void
 public static void _OnClientConnect(ref object de, CLFramework.SRClient net)
 {
     de = new Definitions.Clientdefinition(net);
 }
        public static void Connect(Definitions.Clientdefinition sys)
        {
            //Wrap our code in a try / catch to catch bad exception errors
            try
            {
                //Create a new packet reader to read packet data
                PacketReader Reader = new PacketReader(sys.PacketInformation.buffer);
                //If the first byte = 18 we continue
                if (Reader.Byte() == 18)
                {
                    //First string packet data is for the username
                    string ID = Reader.Text();
                    //Second string packet data is for the password
                    string PW = Reader.Text();

                    byte ReaderBy = Reader.Byte(); //Unknown byte not needed:0xff ?? Country?
                    //Check what server id is requested
                    ushort ShardID = Reader.UInt16();
                    //Set login result
                    ushort lResult = 99;
                    //Set new details for the server in the serverlist
                    Definitions.Serverdef.ServerDetails SSI = Definitions.Serverdef.Serverlist[ShardID];
                    //If the server chosen is not null
                    if (SSI != null)
                    {
                        //TODO: Continue commenting code here
                        ushort myKey   = 0;
                        string sReason = "";
                        lock (Definitions.Serverdef.IPCResultList)
                        {
                            myKey = Definitions.Serverdef.IPCNewId++;
                        }
                        byte[] rqp = Definitions.Serverdef.IPCServer.PacketRequestLogin(Definitions.Serverdef.IPCPort, ID, PW, myKey);
                        Servers.IPCenCode(ref rqp, SSI.code);
                        lock (Definitions.Serverdef.IPCResultList)
                        {
                            Definitions.Serverdef.IPCResultList.Add(myKey, new Definitions.Serverdef.IPCItem());
                            Definitions.Serverdef.IPCResultList[myKey].ResultCode = 0x8000;
                        }
                        Definitions.Serverdef.IPCServer.Send(SSI.ip, SSI.ipcport, rqp);
                        DateTime tOut = DateTime.Now.AddSeconds(30);
                        while ((tOut >= DateTime.Now) && (Definitions.Serverdef.IPCResultList[myKey].ResultCode == 0x8000) && (sys.client.clientSocket.Connected))
                        {
                            System.Threading.Thread.Sleep(10);
                        }
                        lResult = Definitions.Serverdef.IPCResultList[myKey].ResultCode;
                        sReason = Definitions.Serverdef.IPCResultList[myKey].BanReason;
                        lock (Definitions.Serverdef.IPCResultList)
                        {
                            Definitions.Serverdef.IPCResultList[myKey] = null;
                            Definitions.Serverdef.IPCResultList.Remove(myKey);
                        }
                        rqp = null;
                        switch ((LOGIN_RESULT_TYPES)lResult)
                        {
                        case LOGIN_RESULT_TYPES.SERVER_CROWDED:
                            sys.client.Send(Core.Packets.Login.ServerIsFull());
                            sys.client.Disconnect(sys.PacketInformation.Client);
                            return;

                        case LOGIN_RESULT_TYPES.ACCOUNT_NOT_FOUND:
                            sys.client.Send(Core.Packets.Login.WriteMessage("Account ID Not Found.Please register new account www.clowenonline.com"));
                            break;

                        case LOGIN_RESULT_TYPES.ACCOUNT_ALREADY_ONLINE:
                            sys.client.Send(Core.Packets.Login.AllreadyConnected());
                            sys.client.Disconnect(sys.PacketInformation.Client);
                            return;

                        case LOGIN_RESULT_TYPES.ACCOUNT_BANNED:
                            sys.client.Send(Core.Packets.Login.AccountBanned(sReason /*,BannedTime*/));
                            sys.client.Disconnect(sys.PacketInformation.Client);
                            return;

                        case LOGIN_RESULT_TYPES.ACCOUNT_CONNECT_SUCCESSFULY:
                            sys.client.Send(Core.Packets.Login.ConnectSucces(SSI.extip != "" ? SSI.extip : SSI.ip, (Int16)SSI.port, 1));
                            return;

                        case LOGIN_RESULT_TYPES.ACCOUNT_INFORMATION_FAILED:
                            sys.client.Send(Core.Packets.Login.WriteMessage("You have typed wrong ID or PW.Please re-enter your ID or PW."));
                            //sys.client.Send(Core.Packets.Login.PasswordFailed(new Random().Next(1, 16), 16));
                            return;

                        default:
                            sys.client.Send(Core.Packets.Login.WriteMessage("Connection Failed."));
                            sys.client.Disconnect(sys.PacketInformation.Client);
                            if (lResult == 0x8000)
                            {
                                //timeout
                                sys.client.Send(Core.Packets.Login.WriteMessage("Connection Time out.Disconnecting."));
                                sys.client.Disconnect(sys.PacketInformation.Client);
                            }
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }