Esempio n. 1
0
        private void AcceptCallback(IAsyncResult ar)
        {
            this.AcceptDone.Set();
            Socket           asyncState = (Socket)ar.AsyncState;
            ClientConnection connection = new ClientConnection();

            connection.ConnectionSocket = asyncState.EndAccept(ar);
            Console.WriteLine("Accepting new connection (socket " + connection.ConnectionSocket.Handle.ToString() + ")");
            lock (ServerBase.AuthCores)
            {
                Core core = (Core)ServerBase.AuthCores[0];
                foreach (Core core2 in ServerBase.AuthCores)
                {
                    if (core2.ConnectedClients.Count <= core.ConnectedClients.Count)
                    {
                        core = core2;
                    }
                }
                connection.CoreID = core.CoreID;
                core.NewClients.Add(connection);
            }
            try
            {
                ByteArrayBuilderV2 data = new ByteArrayBuilderV2();
                data.Add((uint)0xdeadbabe);
                connection.Send(OpCodes.SMSG_AUTH_CHALLENGE, data);
                connection.ConnectionSocket.BeginReceive(connection.Buffer, 0, connection.Buffer.Length, SocketFlags.None, new AsyncCallback(connection.ReadCallback), connection);
            }
            catch (SocketException exception)
            {
                Console.WriteLine(exception);
            }
        }
        public OpCodes GetOP(ByteArrayBuilderV2 data)
        {
            this.input.Clear();
            int     length = data.Length;
            OpCodes codes  = OpCodes.MSG_NULL_ACTION;

            for (int i = 0; i < length; i++)
            {
                this.input.Add(data[i]);
            }
            while (this.input.Length >= 6)
            {
                if (this.needDecode && (this.User.Hash != null))
                {
                    this.Decode(this.input);
                    this.needDecode = false;
                }
                this.input.pos = 0;
                ushort num3 = Endian.Swap(this.input.GetWord());
                if (this.input.Length < (num3 + 2))
                {
                    return(OpCodes.MSG_NULL_ACTION);
                }
                this.needDecode = true;
                data            = this.input.GetArray(4, num3 - 2);
                codes           = (OpCodes)(this.input[2] + (this.input[3] << 8));
                this.input.Remove(0, num3 + 2);
            }
            return(codes);
        }
        public OpCodes GetOP(ByteArrayBuilderV2 data)
        {
            this.PacketLength = 0;
            int num  = 0;
            int num2 = 0;

            this.input.Clear();
            OpCodes codes = OpCodes.MSG_NULL_ACTION;

            this.input.Add((byte[])data);
            while (this.input.Length >= 6)
            {
                if (this.User.Hash != null)
                {
                    this.Decode(this.input);
                }
                num++;
                this.input.pos = 0;
                ushort num3 = Endian.Swap(this.input.GetWord());
                num2 += num3;
                codes = (OpCodes)(this.input[2] + (this.input[3] << 8));
                this.input.Remove(0, num3 + 2);
            }
            this.PacketLength = num2 + (num * 2);
            return(codes);
        }
        public void ReadCallback(IAsyncResult ar)
        {
            ArrayList list;

            lock ((list = this.Packets))
            {
                if (this.CanBeCleared)
                {
                    this.Packets.Clear();
                }
            }
            int count = 0;

            try
            {
                count = this.ConnectionSocket.EndReceive(ar);
                if (count <= 0x400)
                {
                    this.temp.Clear();
                    this.temp.Add(this.Buffer);
                    lock (this.DataBuffer)
                    {
                        this.DataBuffer.Add(this.temp.GetArray(0, count));
                    }
                }
                if (this.ConnectionSocket.Available > 0)
                {
                    this.Buffer = new byte[0x400];
                    this.ConnectionSocket.BeginReceive(this.Buffer, 0, this.Buffer.Length, SocketFlags.None, new AsyncCallback(this.ReadCallback), null);
                    return;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                this.Disconnect();
            }
            if (count <= 0)
            {
                this.Disconnect();
            }
            else
            {
                lock ((list = this.Packets))
                {
                    this.Packets.Add(this.DataBuffer);
                    this.DataBuffer = new ByteArrayBuilderV2();
                }
                this.Buffer = new byte[0x400];
                try
                {
                    this.ConnectionSocket.BeginReceive(this.Buffer, 0, this.Buffer.Length, SocketFlags.None, new AsyncCallback(this.ReadCallback), null);
                }
                catch (SocketException exception2)
                {
                    Console.WriteLine(exception2);
                    this.Disconnect();
                }
            }
        }
 private void BuildMovementUpdate(ObjectBase o, byte flags, uint flags2, ByteArrayBuilderV2 update)
 {
     update.Add(flags);
     if (o.ObjectTypeID == TYPEID.PLAYER)
     {
         update.Add(flags2);
         update.Add((uint)0xb74d85d1);
         update.Add(o.x);
         update.Add(o.y);
         update.Add(o.z);
         update.Add(o.o);
         update.Add((float)0f);
         if (flags2 == 0x2000)
         {
             update.Add((float)0f);
             update.Add((float)1f);
             update.Add((float)0f);
             update.Add((float)0f);
         }
         update.Add(Speeds.walkspeed);
         update.Add(Speeds.runspeed);
         update.Add(Speeds.backwardspeed);
         update.Add(Speeds.sweemspeed);
         update.Add(Speeds.sweembackspeed);
         update.Add(Speeds.turn);
         update.Add((uint)1);
     }
     else
     {
         update.Add((uint)1);
     }
 }
 public void BuildUpdate(ByteArrayBuilderV2 pack)
 {
     pack.Add((byte)this.mask.Length);
     pack.Add(this.mask);
     foreach (uint num in this.updateValues.Values)
     {
         pack.Add(num);
     }
 }
 public void BuildUpdate(ByteArrayBuilderV2 pack)
 {
     pack.Add((byte)this.mask.Length);
     pack.Add(this.mask);
     for (int i = 0; i < this.data.Length; i++)
     {
         if (this.data[i] != null)
         {
             pack.Add((byte[])this.data[i]);
         }
     }
 }
        public ByteArrayBuilderV2 SendAddonPacket(ClientConnection Client, ByteArrayBuilderV2 Data)
        {
            ByteArrayBuilderV2 rv = new ByteArrayBuilderV2();

            for (int i = 0; i < 12; i++)
            {
                rv.Add((byte)2);
                rv.Add((byte)1);
                rv.Add((uint)0);
                rv.Add((ushort)0);
            }
            return(rv);
        }
        public byte[] DeleteCharacter(ByteArrayBuilderV2 data, ClientConnection Client, DatabaseManager DbManager)
        {
            ulong num;
            ByteArrayBuilderV2 rv = new ByteArrayBuilderV2();

            data.Get(out num);
            if (DbManager.Write("DELETE FROM characters WHERE guid='" + num.ToString() + "'") < 1)
            {
                rv.Add((byte)0x36);
                return((byte[])rv);
            }
            rv.Add((byte)0x39);
            return((byte[])rv);
        }
 private void Encode(ByteArrayBuilderV2 data)
 {
     for (int i = 0; i < 4; i++)
     {
         byte index = this.key[3];
         index = (byte)(this.User.Hash[index] ^ data[i]);
         byte num3 = this.key[2];
         index       = (byte)(index + num3);
         data[i]     = index;
         this.key[2] = index;
         index       = this.key[3];
         index       = (byte)(index + 1);
         this.key[3] = (byte)(index % 40);
     }
 }
 public void Run(ClientConnection Client)
 {
     if ((Client.LogoutTimer != null) && Client.LogoutTimer.IsExpired())
     {
         ByteArrayBuilderV2 data = new ByteArrayBuilderV2();
         data.Add((byte)0);
         data.Add((uint)0);
         Client.Send(OpCodes.SMSG_LOGOUT_COMPLETE, data);
         Console.WriteLine(Client.PlayerBase.name + " logged out");
         Client.LogoutTimer = null;
         lock (StaticCore.RealmDbManager)
         {
             StaticCore.RealmDbManager.Write("UPDATE realms SET onlineplayers=onlineplayers-1 WHERE id='" + StaticCore.RealmID.ToString() + "'");
         }
     }
 }
 public void Send(OpCodes op, ByteArrayBuilderV2 data)
 {
     this.pack.Clear();
     this.pack.Add(Endian.Swap((ushort)(data.Length + 2)));
     this.pack.Add((ushort)op);
     this.pack.Add((byte[])data);
     if (this.User.Hash != null)
     {
         this.Encode(this.pack);
         this.Send((byte[])this.pack);
     }
     else
     {
         this.Send((byte[])this.pack);
     }
 }
 private void Decode(ByteArrayBuilderV2 data)
 {
     for (int i = 0; i < 6; i++)
     {
         byte num2 = this.key[0];
         this.key[0] = data[i];
         byte num3 = data[i];
         num3 = (byte)(num3 - num2);
         byte index = this.key[1];
         num2        = this.User.Hash[index];
         num2        = (byte)(num2 ^ num3);
         data[i]     = num2;
         num2        = this.key[1];
         num2        = (byte)(num2 + 1);
         this.key[1] = (byte)(num2 % 40);
     }
 }
        public void Move(ClientConnection Client, ByteArrayBuilderV2 Data)
        {
            uint  num;
            uint  num2;
            float num3;
            float num4;
            float num5;
            float num6;

            Data.Get(out num);
            Data.Get(out num2);
            Data.Get(out num3);
            Data.Get(out num4);
            Data.Get(out num5);
            Data.Get(out num6);
            Console.WriteLine("X:{0} Y:{1} Z:{2} O:{3}", new object[] { num3, num4, num5, num6 });
        }
Esempio n. 15
0
        public void Login(ClientConnection Client, ulong guid)
        {
            ByteArrayBuilderV2 data = new ByteArrayBuilderV2();

            foreach (CharacterBase base2 in Client.Characters)
            {
                if (base2.guid == guid)
                {
                    Client.PlayerBase = base2;
                }
            }
            if (Client.PlayerBase == null)
            {
                Client.Disconnect();
            }
            else
            {
                lock (StaticCore.RealmDbManager)
                {
                    StaticCore.RealmDbManager.Write("UPDATE realms SET onlineplayers=onlineplayers+1 WHERE id='" + StaticCore.RealmID.ToString() + "'");
                }
                Client.PlayerBase.ObjectsInRange = new Hashtable();
                Client.Send(OpCodes.SMSG_ACCOUNT_DATA_MD5, new byte[80]);
                data.Add(Client.PlayerBase.tutorialflags);
                Client.Send(OpCodes.SMSG_TUTORIAL_FLAGS, data);
                data.Clear();
                data.Add(this.GetTimeStamp());
                data.Add((float)0.017f);
                Client.Send(OpCodes.SMSG_LOGIN_SETTIMESPEED, data);
                Client.PlayerBase.PowerType = Client.PlayerBase.GetPowerType();
                Client.PlayerBase.BaseObject.Create(Client.PlayerBase, Client);
                UpdateBuilder builder = new UpdateBuilder();
                builder.AddObject(Client.PlayerBase.BaseObject);
                builder.CreateUpdate(Client.PlayerBase.guid);
                Client.Send(OpCodes.SMSG_UPDATE_OBJECT, builder.GetUpdate());
                Client.Send(OpCodes.SMSG_MOVE_UNLOCK_MOVEMENT, new byte[4]);
                new ChatHandler().SendWelcome(Client, "Welcome to Scarabeus Server (alpha)\nEnjoy your stay!");
            }
        }
Esempio n. 16
0
        public byte[] CreateCharacter(ByteArrayBuilderV2 data, ClientConnection Client, DatabaseManager DbManager)
        {
            byte num;
            byte num2;
            byte num3;
            byte num4;
            ByteArrayBuilderV2 rv = new ByteArrayBuilderV2();

            if (Client.Characters.Count >= 10)
            {
                rv.Add((byte)0x34);
                return((byte[])rv);
            }
            CharacterBase base2 = new CharacterBase();

            data.Get(out base2.name);
            this.Reader = DbManager.Read("SELECT guid FROM characters WHERE name='" + base2.name + "'");
            if (this.Reader.Read())
            {
                rv.Add((byte)0x31);
                this.Reader.Close();
                return((byte[])rv);
            }
            this.Reader.Close();
            data.Get(out num);
            data.Get(out num2);
            base2.class_ = (Classes)num2;
            base2.race   = (Races)num;
            if ((Client.User.GMLevel < 1) && (Client.User.team != Side.NONE))
            {
                if ((Client.User.team != base2.GetSide()) && (StaticCore.RealmType == 1))
                {
                    rv.Add((byte)0x33);
                    return((byte[])rv);
                }
                if ((Client.User.team != base2.GetSide()) && (StaticCore.RealmType == 8))
                {
                    rv.Add((byte)0x33);
                    return((byte[])rv);
                }
            }
            data.Get(out num3);
            base2.gender = (Gender)num3;
            data.Get(out base2.skin);
            data.Get(out base2.face);
            data.Get(out base2.hairstyle);
            data.Get(out base2.haircolor);
            data.Get(out base2.facialhair);
            data.Get(out num4);
            base2.level     = 1;
            base2.displayid = base2.GetDisplayId();
            string[] strArray = new string[] { "SELECT * FROM playercreateinfo WHERE race='", ((byte)base2.race).ToString(), "' AND class='", ((byte)base2.class_).ToString(), "'" };
            this.Reader = DbManager.Read(string.Concat(strArray));
            this.Reader.Read();
            base2.map    = this.Reader.GetUInt32(2);
            base2.zoneid = this.Reader.GetUInt32(3);
            base2.x      = this.Reader.GetFloat(4);
            base2.y      = this.Reader.GetFloat(5);
            base2.z      = this.Reader.GetFloat(6);
            this.Reader.Close();
            MySqlCommand command = new MySqlCommand();

            command.Connection  = DbManager.Connection;
            command.CommandText = "INSERT INTO characters (accname, name, race, class, gender, skin, face, hairstyle, haircolor, facialhair, level, zoneid, map, x, y, z, guildid, flags, rest, petinfoid, petlevel, petfamilyid, realmid, displayid, tutorialflags) VALUES(?accname, ?name, ?race, ?class, ?gender, ?skin, ?face, ?hairstyle, ?haircolor, ?facialhair, ?level, ?zoneid, ?map, ?x, ?y, ?z, ?guildid, ?flags, ?rest, ?petinfoid, ?petlevel, ?petfamilyid, ?realmid, ?displayid, ?tutorialflags)";
            command.Parameters.Add("?accname", Client.User.Name);
            command.Parameters.Add("?name", base2.name);
            command.Parameters.Add("?race", base2.race);
            command.Parameters.Add("?class", base2.class_);
            command.Parameters.Add("?gender", base2.gender);
            command.Parameters.Add("?skin", base2.skin);
            command.Parameters.Add("?face", base2.face);
            command.Parameters.Add("?hairstyle", base2.hairstyle);
            command.Parameters.Add("?haircolor", base2.haircolor);
            command.Parameters.Add("?facialhair", base2.facialhair);
            command.Parameters.Add("?level", base2.level);
            command.Parameters.Add("?zoneid", base2.zoneid);
            command.Parameters.Add("?map", base2.map);
            command.Parameters.Add("?x", base2.x);
            command.Parameters.Add("?y", base2.y);
            command.Parameters.Add("?z", base2.z);
            command.Parameters.Add("?guildid", base2.guildid);
            command.Parameters.Add("?flags", base2.flags);
            command.Parameters.Add("?rest", base2.rest);
            command.Parameters.Add("?petinfoid", base2.petinfoid);
            command.Parameters.Add("?petlevel", base2.petlevel);
            command.Parameters.Add("?petfamilyid", base2.petfamilyid);
            command.Parameters.Add("?realmid", StaticCore.RealmID);
            command.Parameters.Add("?displayid", base2.displayid);
            command.Parameters.Add("?tutorialflags", base2.tutorialflags);
            if (command.ExecuteNonQuery() < 1)
            {
                rv.Add((byte)0x30);
                return((byte[])rv);
            }
            rv.Add((byte)0x2e);
            return((byte[])rv);
        }
Esempio n. 17
0
        private void PacketHandle(ClientConnection Client)
        {
            ArrayList list = new ArrayList();

            lock (Client.Packets)
            {
                foreach (ByteArrayBuilderV2 rv in Client.Packets)
                {
                    list.Add(rv);
                }
                Client.Packets.Clear();
            }
            foreach (ByteArrayBuilderV2 rv2 in list)
            {
                ulong num5;
                this.Timer.Run(Client);
                OpCodes oP = Client.GetOP(rv2);
                Console.WriteLine(oP.ToString());
                this.OutPacket.Clear();
                rv2.pos = 6;
                switch (oP)
                {
                case OpCodes.CMSG_PLAYER_LOGOUT:
                    this.logout = new LogoutHandler();
                    this.logout.LogoutRequest(0, Client);
                    goto Label_0E44;

                case OpCodes.CMSG_LOGOUT_REQUEST:
                    this.logout = new LogoutHandler();
                    this.logout.LogoutRequest(0x4e20, Client);
                    goto Label_0E44;

                case OpCodes.CMSG_LOGOUT_CANCEL:
                    this.logout.CancelLogout(Client);
                    goto Label_0E44;

                case OpCodes.CMSG_NAME_QUERY:
                    rv2.Get(out num5);
                    Console.WriteLine("name guid:{0}", num5);
                    if (num5 != Client.PlayerBase.guid)
                    {
                        break;
                    }
                    this.OutPacket.Add(Client.PlayerBase.guid);
                    this.OutPacket.Add(Client.PlayerBase.name);
                    this.OutPacket.Add((byte)0);
                    this.OutPacket.Add((uint)Client.PlayerBase.race);
                    this.OutPacket.Add((uint)Client.PlayerBase.gender);
                    this.OutPacket.Add((uint)Client.PlayerBase.class_);
                    Client.Send(OpCodes.SMSG_NAME_QUERY_RESPONSE, this.OutPacket);
                    goto Label_0E44;

                case OpCodes.CMSG_ITEM_QUERY_SINGLE:
                    ulong num9;
                    uint  num10;
                    rv2.Get(out num10);
                    rv2.Get(out num9);
                    Console.WriteLine("\nitem entry: " + num10.ToString() + " guid: " + num9.ToString());
                    this.OutPacket.Add(num10);
                    this.OutPacket.Add((uint)4);
                    this.OutPacket.Add((uint)1);
                    this.OutPacket.Add("Circle of Flame");
                    this.OutPacket.Add("qname");
                    this.OutPacket.Add("honorname");
                    this.OutPacket.Add("enchname");
                    this.OutPacket.Add((uint)0x6e6c);
                    this.OutPacket.Add((uint)4);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)100);
                    this.OutPacket.Add((uint)10);
                    this.OutPacket.Add((uint)1);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0x3b);
                    this.OutPacket.Add((uint)1);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)1);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add(new byte[0x48]);
                    this.OutPacket.Add((uint)7);
                    this.OutPacket.Add((uint)100);
                    this.OutPacket.Add(new byte[60]);
                    this.OutPacket.Add((uint)5);
                    this.OutPacket.Add((uint)10);
                    this.OutPacket.Add((uint)5);
                    this.OutPacket.Add((uint)20);
                    this.OutPacket.Add((uint)5);
                    this.OutPacket.Add((uint)50);
                    this.OutPacket.Add((uint)10);
                    this.OutPacket.Add(new byte[120]);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    this.OutPacket.Add((uint)0);
                    Client.Send(OpCodes.SMSG_ITEM_QUERY_SINGLE_RESPONSE, this.OutPacket);
                    goto Label_0E44;

                case OpCodes.CMSG_PLAYER_LOGIN:
                {
                    ulong      num4;
                    EnterWorld world = new EnterWorld();
                    rv2.Get(out num4);
                    Console.WriteLine("PlayerBase guid:{0}", num4);
                    this.DbManager.Write("UPDATE characters SET online=1 WHERE guid='" + num4.ToString() + "'");
                    world.Login(Client, num4);
                    goto Label_0E44;
                }

                case OpCodes.CMSG_CHAR_CREATE:
                {
                    CHAR_CREATE_Handler handler2 = new CHAR_CREATE_Handler();
                    Client.Send(OpCodes.SMSG_CHAR_CREATE, handler2.CreateCharacter(rv2, Client, this.DbManager));
                    goto Label_0E44;
                }

                case OpCodes.CMSG_CHAR_ENUM:
                case OpCodes.CMSG_UNKNOWN_908:
                {
                    CHAR_ENUM_Handler handler = new CHAR_ENUM_Handler();
                    Client.Send(OpCodes.SMSG_CHAR_ENUM, handler.CreateList(Client, this.DbManager));
                    goto Label_0E44;
                }

                case OpCodes.CMSG_CHAR_DELETE:
                {
                    CHAR_DELETE_Handler handler3 = new CHAR_DELETE_Handler();
                    Client.Send(OpCodes.SMSG_CHAR_DELETE, handler3.DeleteCharacter(rv2, Client, this.DbManager));
                    goto Label_0E44;
                }

                case OpCodes.MSG_NULL_ACTION:
                    Client.Disconnect();
                    goto Label_0E44;

                case OpCodes.MSG_MOVE_START_FORWARD:
                case OpCodes.MSG_MOVE_START_BACKWARD:
                case OpCodes.MSG_MOVE_STOP:
                case OpCodes.MSG_MOVE_START_STRAFE_LEFT:
                case OpCodes.MSG_MOVE_START_STRAFE_RIGHT:
                case OpCodes.MSG_MOVE_STOP_STRAFE:
                case OpCodes.MSG_MOVE_JUMP:
                case OpCodes.MSG_MOVE_START_TURN_LEFT:
                case OpCodes.MSG_MOVE_START_TURN_RIGHT:
                case OpCodes.MSG_MOVE_STOP_TURN:
                case OpCodes.MSG_MOVE_START_PITCH_UP:
                case OpCodes.MSG_MOVE_START_PITCH_DOWN:
                case OpCodes.MSG_MOVE_STOP_PITCH:
                case OpCodes.MSG_MOVE_SET_RUN_MODE:
                case OpCodes.MSG_MOVE_SET_WALK_MODE:
                case OpCodes.MSG_MOVE_START_SWIM:
                case OpCodes.MSG_MOVE_STOP_SWIM:
                case OpCodes.MSG_MOVE_SET_FACING:
                case OpCodes.MSG_MOVE_SET_PITCH:
                case OpCodes.MSG_MOVE_HEARTBEAT:
                    this.Movement.Move(Client, rv2);
                    goto Label_0E44;

                case OpCodes.CMSG_MESSAGECHAT:
                case OpCodes.CMSG_UPDATE_ACCOUNT_DATA:
                case OpCodes.CMSG_GMTICKET_GETTICKET:
                case OpCodes.CMSG_SET_ACTIVE_MOVER:
                case OpCodes.CMSG_MEETINGSTONE_INFO:
                case OpCodes.CMSG_MOVE_TIME_SKIPPED:
                case OpCodes.CMSG_BATTLEFIELD_STATUS:
                    goto Label_0E44;

                case OpCodes.CMSG_TUTORIAL_FLAG:
                    uint num6;
                    rv2.Get(out num6);
                    this.DbManager.Write("UPDATE characters SET tutorialflags='" + num6.ToString() + "' WHERE guid='" + Client.PlayerBase.guid.ToString() + "'");
                    goto Label_0E44;

                case OpCodes.CMSG_TUTORIAL_CLEAR:
                {
                    string[] strArray = new string[] { "UPDATE characters SET tutorialflags='", uint.MaxValue.ToString(), "' WHERE guid='", Client.PlayerBase.guid.ToString(), "'" };
                    this.DbManager.Write(string.Concat(strArray));
                    goto Label_0E44;
                }

                case OpCodes.CMSG_TUTORIAL_RESET:
                    this.DbManager.Write("UPDATE characters SET tutorialflags=0 WHERE guid='" + Client.PlayerBase.guid.ToString() + "'");
                    goto Label_0E44;

                case OpCodes.CMSG_PING:
                    uint num3;
                    rv2.Get(out num3);
                    this.OutPacket.Add(num3);
                    Client.Send(OpCodes.SMSG_PONG, this.OutPacket);
                    goto Label_0E44;

                case OpCodes.CMSG_AUTH_SESSION:
                {
                    uint            num;
                    uint            num2;
                    DatabaseManager manager;
                    rv2.Get(out num);
                    rv2.Seek(4);
                    rv2.Get(out Client.User.Name);
                    Client.User.Name = Client.User.Name.ToLower();
                    Client.User.Hash = new byte[40];
                    rv2.Get(out num2);
                    byte[] array = rv2.GetArray(20);
                    lock ((manager = StaticCore.RealmDbManager))
                    {
                        this.MySqlReader = StaticCore.RealmDbManager.Read("SELECT sessionkey, level, burning FROM accounts WHERE name='" + Client.User.Name + "'");
                    }
                    if (!this.MySqlReader.Read())
                    {
                        Client.Disconnect();
                        this.MySqlReader.Close();
                    }
                    else
                    {
                        this.MySqlReader.GetBytes(0, (long)0, Client.User.Hash, 0, 40);
                        Client.User.GMLevel   = this.MySqlReader.GetInt32(1);
                        Client.User.BCEnabled = this.MySqlReader.GetBoolean(2);
                        this.MySqlReader.Close();
                        lock ((manager = StaticCore.RealmDbManager))
                        {
                            StaticCore.RealmDbManager.Write("UPDATE accounts SET inworld=1, lastrealmid='" + StaticCore.RealmID.ToString() + "' WHERE name='" + Client.User.Name + "'");
                        }
                        SHA1 sha = new SHA1CryptoServiceProvider();
                        ByteArrayBuilderV2 rv3 = new ByteArrayBuilderV2();
                        rv3.Add(Encoding.ASCII.GetBytes(Client.User.Name.ToUpper()));
                        rv3.Add((uint)0);
                        rv3.Add(num2);
                        rv3.Add((uint)0xdeadbabe);
                        rv3.Add(Client.User.Hash);
                        if (!WorldServer.Utils.IsSameByteArray(sha.ComputeHash((byte[])rv3), array))
                        {
                            this.OutPacket.Add((byte)13);
                            Client.Send(OpCodes.SMSG_AUTH_RESPONSE, this.OutPacket);
                        }
                        else if (num != 0x1992)
                        {
                            this.OutPacket.Add((byte)13);
                            Client.Send(OpCodes.SMSG_AUTH_RESPONSE, this.OutPacket);
                        }
                        else
                        {
                            this.OutPacket.Add((byte)12);
                            this.OutPacket.Add((byte)0xb0);
                            this.OutPacket.Add((byte)9);
                            this.OutPacket.Add((byte)2);
                            this.OutPacket.Add((byte)0);
                            this.OutPacket.Add((byte)2);
                            this.OutPacket.Add((uint)0);
                            if (Client.User.BCEnabled)
                            {
                                this.OutPacket.Add((byte)1);
                            }
                            else
                            {
                                this.OutPacket.Add((byte)0);
                            }
                            Client.Send(OpCodes.SMSG_AUTH_RESPONSE, this.OutPacket);
                        }
                    }
                    goto Label_0E44;
                }

                case OpCodes.CMSG_SWAP_INV_ITEM:
                    byte num7;
                    byte num8;
                    rv2.Get(out num7);
                    rv2.Get(out num8);
                    Console.WriteLine("from: {0} to: {1}", num7, num8);
                    this.OutPacket.Add((byte)4);
                    this.OutPacket.Add((ulong)400);
                    this.OutPacket.Add((ulong)0);
                    this.OutPacket.Add((byte)0);
                    Client.Send(OpCodes.SMSG_INVENTORY_CHANGE_FAILURE, this.OutPacket);
                    goto Label_0E44;

                case OpCodes.CMSG_QUERY_TIME:
                    this.OutPacket.Add((uint)0);
                    Client.Send(OpCodes.SMSG_QUERY_TIME_RESPONSE, this.OutPacket);
                    goto Label_0E44;

                case OpCodes.CMSG_REQUEST_RAID_INFO:
                    this.OutPacket.Add((uint)0);
                    Client.Send(OpCodes.SMSG_RAID_INSTANCE_INFO, this.OutPacket);
                    goto Label_0E44;

                default:
                    WorldServer.Utils.konzol((byte[])rv2);
                    Console.WriteLine("unhandled OpCode (" + oP.ToString() + ")");
                    goto Label_0E44;
                }
                this.MySqlReader = this.DbManager.Read("SELECT name, race, class, gender FROM characters WHERE guid='" + num5.ToString() + "'");
                if (!this.MySqlReader.Read())
                {
                    this.MySqlReader.Close();
                }
                else
                {
                    this.OutPacket.Add(num5);
                    this.OutPacket.Add(this.MySqlReader[0].ToString());
                    this.OutPacket.Add((byte)0);
                    this.OutPacket.Add((uint)this.MySqlReader.GetByte(1));
                    this.OutPacket.Add((uint)this.MySqlReader.GetByte(3));
                    this.OutPacket.Add((uint)this.MySqlReader.GetByte(2));
                    this.MySqlReader.Close();
                    Client.Send(OpCodes.SMSG_NAME_QUERY_RESPONSE, this.OutPacket);
                }
                Label_0E44 :;
            }
        }
Esempio n. 18
0
        private void PacketHandle(ClientConnection Client)
        {
            this.Timer.Run(Client);
            if (Client.Data.Length > 1)
            {
                OpCodes oP = Client.GetOP(Client.Data);
                Console.WriteLine(oP.ToString());
                this.OutPacket.Clear();
                Client.Data.Seek(6);
                switch (oP)
                {
                case OpCodes.CMSG_CHAR_CREATE:
                {
                    CHAR_CREATE_Handler handler2 = new CHAR_CREATE_Handler();
                    Client.Send(OpCodes.SMSG_CHAR_CREATE, handler2.CreateCharacter(Client.Data, Client, this.DbManager));
                    break;
                }

                case OpCodes.CMSG_CHAR_ENUM:
                {
                    CHAR_ENUM_Handler handler = new CHAR_ENUM_Handler();
                    Client.Send(OpCodes.SMSG_CHAR_ENUM, handler.CreateList(Client, this.DbManager));
                    break;
                }

                case OpCodes.CMSG_CHAR_DELETE:
                {
                    CHAR_DELETE_Handler handler3 = new CHAR_DELETE_Handler();
                    Client.Send(OpCodes.SMSG_CHAR_DELETE, handler3.DeleteCharacter(Client.Data, Client, this.DbManager));
                    break;
                }

                case OpCodes.CMSG_PLAYER_LOGIN:
                {
                    ulong      num4;
                    EnterWorld world = new EnterWorld();
                    Client.Data.Get(out num4);
                    this.DbManager.Write("UPDATE characters SET online=1 WHERE guid='" + num4.ToString() + "'");
                    world.Login(Client, num4);
                    break;
                }

                case OpCodes.MSG_NULL_ACTION:
                    Client.Disconnect();
                    break;

                case OpCodes.CMSG_TUTORIAL_FLAG:
                    uint num6;
                    Client.Data.Get(out num6);
                    this.DbManager.Write("UPDATE characters SET tutorialflags='" + num6.ToString() + "' WHERE guid='" + Client.PlayerBase.guid.ToString() + "'");
                    break;

                case OpCodes.CMSG_TUTORIAL_CLEAR:
                {
                    string[] strArray = new string[] { "UPDATE characters SET tutorialflags='", uint.MaxValue.ToString(), "' WHERE guid='", Client.PlayerBase.guid.ToString(), "'" };
                    this.DbManager.Write(string.Concat(strArray));
                    break;
                }

                case OpCodes.CMSG_TUTORIAL_RESET:
                    this.DbManager.Write("UPDATE characters SET tutorialflags=0 WHERE guid='" + Client.PlayerBase.guid.ToString() + "'");
                    break;

                case OpCodes.CMSG_QUERY_TIME:
                    this.OutPacket.Add((uint)0);
                    Client.Send(OpCodes.SMSG_QUERY_TIME_RESPONSE, this.OutPacket);
                    break;

                case OpCodes.CMSG_PLAYER_LOGOUT:
                    this.logout = new LogoutHandler();
                    this.logout.LogoutRequest(0, Client);
                    break;

                case OpCodes.CMSG_LOGOUT_REQUEST:
                    this.logout = new LogoutHandler();
                    this.logout.LogoutRequest(0x4e20, Client);
                    break;

                case OpCodes.CMSG_LOGOUT_CANCEL:
                    this.logout.CancelLogout(Client);
                    break;

                case OpCodes.CMSG_NAME_QUERY:
                    ulong num5;
                    Client.Data.Get(out num5);
                    if (num5 != Client.PlayerBase.guid)
                    {
                        this.MySqlReader = this.DbManager.Read("SELECT name, race, class, gender FROM characters WHERE guid='" + num5.ToString() + "'");
                        if (!this.MySqlReader.Read())
                        {
                            this.MySqlReader.Close();
                        }
                        else
                        {
                            this.OutPacket.Add(num5);
                            this.OutPacket.Add(this.MySqlReader[0].ToString());
                            this.OutPacket.Add((byte)0);
                            this.OutPacket.Add((uint)this.MySqlReader.GetByte(1));
                            this.OutPacket.Add((uint)this.MySqlReader.GetByte(3));
                            this.OutPacket.Add((uint)this.MySqlReader.GetByte(2));
                            this.MySqlReader.Close();
                            Client.Send(OpCodes.SMSG_NAME_QUERY_RESPONSE, this.OutPacket);
                        }
                    }
                    else
                    {
                        this.OutPacket.Add(Client.PlayerBase.guid);
                        this.OutPacket.Add(Client.PlayerBase.name);
                        this.OutPacket.Add((byte)0);
                        this.OutPacket.Add((uint)Client.PlayerBase.race);
                        this.OutPacket.Add((uint)Client.PlayerBase.gender);
                        this.OutPacket.Add((uint)Client.PlayerBase.class_);
                        Client.Send(OpCodes.SMSG_NAME_QUERY_RESPONSE, this.OutPacket);
                    }
                    break;

                case OpCodes.CMSG_MESSAGECHAT:
                case OpCodes.CMSG_UPDATE_ACCOUNT_DATA:
                case OpCodes.CMSG_GMTICKET_GETTICKET:
                case OpCodes.CMSG_SET_ACTIVE_MOVER:
                case OpCodes.CMSG_MEETINGSTONE_INFO:
                case OpCodes.CMSG_MOVE_TIME_SKIPPED:
                case OpCodes.CMSG_BATTLEFIELD_STATUS:
                    break;

                case OpCodes.CMSG_PING:
                    uint num3;
                    Client.Data.Get(out num3);
                    this.OutPacket.Add(num3);
                    Client.Send(OpCodes.SMSG_PONG, this.OutPacket);
                    break;

                case OpCodes.CMSG_AUTH_SESSION:
                {
                    uint            num;
                    uint            num2;
                    DatabaseManager manager;
                    Client.Data.Get(out num);
                    Client.Data.Seek(4);
                    Client.Data.Get(out Client.User.Name);
                    Client.User.Name = Client.User.Name.ToLower();
                    Client.User.Hash = new byte[40];
                    Client.Data.Get(out num2);
                    byte[] array = Client.Data.GetArray(20);
                    lock ((manager = StaticCore.RealmDbManager))
                    {
                        this.MySqlReader = StaticCore.RealmDbManager.Read("SELECT sessionkey, level FROM accounts WHERE name='" + Client.User.Name + "'");
                    }
                    if (!this.MySqlReader.Read())
                    {
                        Client.Disconnect();
                        this.MySqlReader.Close();
                    }
                    else
                    {
                        this.MySqlReader.GetBytes(0, (long)0, Client.User.Hash, 0, 40);
                        Client.User.GMLevel = this.MySqlReader.GetInt32(1);
                        this.MySqlReader.Close();
                        lock ((manager = StaticCore.RealmDbManager))
                        {
                            StaticCore.RealmDbManager.Write("UPDATE accounts SET inworld=1, lastrealmid='" + StaticCore.RealmID.ToString() + "' WHERE name='" + Client.User.Name + "'");
                        }
                        SHA1 sha = new SHA1CryptoServiceProvider();
                        ByteArrayBuilderV2 rv = new ByteArrayBuilderV2();
                        rv.Add(Encoding.ASCII.GetBytes(Client.User.Name.ToUpper()));
                        rv.Add((uint)0);
                        rv.Add(num2);
                        rv.Add((uint)0xdeadbabe);
                        rv.Add(Client.User.Hash);
                        if (!WorldServer.Utils.IsSameByteArray(sha.ComputeHash((byte[])rv), array))
                        {
                            this.OutPacket.Add((byte)13);
                            Client.Send(OpCodes.SMSG_AUTH_RESPONSE, this.OutPacket);
                        }
                        else if (num != 0x16f3)
                        {
                            this.OutPacket.Add((byte)13);
                            Client.Send(OpCodes.SMSG_AUTH_RESPONSE, this.OutPacket);
                        }
                        else
                        {
                            this.OutPacket.Add((byte)12);
                            Client.Send(OpCodes.SMSG_AUTH_RESPONSE, this.OutPacket);
                        }
                    }
                    break;
                }

                case OpCodes.CMSG_REQUEST_RAID_INFO:
                    this.OutPacket.Add((uint)0);
                    Client.Send(OpCodes.SMSG_RAID_INSTANCE_INFO, this.OutPacket);
                    break;

                default:
                    Console.WriteLine("unhandled OpCode (" + oP.ToString() + ")");
                    break;
                }
                Client.MRE.Set();
            }
        }
Esempio n. 19
0
 public void GetMask(ByteArrayBuilderV2 pack)
 {
     pack.Add(this.mask);
 }
Esempio n. 20
0
        public byte[] CreateList(ClientConnection Client, DatabaseManager DbManager)
        {
            Client.PlayerBase = null;
            ByteArrayBuilderV2 rv = new ByteArrayBuilderV2();

            this.Reader       = DbManager.Read("SELECT * FROM characters WHERE accname='" + Client.User.Name + "' AND realmid='" + StaticCore.RealmID.ToString() + "'");
            Client.Characters = new ArrayList();
            while (this.Reader.Read())
            {
                CharacterBase base2 = new CharacterBase();
                base2.guid = this.Reader.GetUInt64(0);
                base2.name = this.Reader[2].ToString();
                byte @byte = this.Reader.GetByte(3);
                byte num2  = this.Reader.GetByte(4);
                byte num3  = this.Reader.GetByte(5);
                base2.gender        = (Gender)num3;
                base2.race          = (Races)@byte;
                base2.class_        = (Classes)num2;
                base2.skin          = this.Reader.GetByte(6);
                base2.face          = this.Reader.GetByte(7);
                base2.hairstyle     = this.Reader.GetByte(8);
                base2.haircolor     = this.Reader.GetByte(9);
                base2.facialhair    = this.Reader.GetByte(10);
                base2.level         = this.Reader.GetByte(11);
                base2.zoneid        = this.Reader.GetUInt32(12);
                base2.map           = this.Reader.GetUInt32(13);
                base2.x             = this.Reader.GetFloat(14);
                base2.y             = this.Reader.GetFloat(15);
                base2.z             = this.Reader.GetFloat(0x10);
                base2.guildid       = this.Reader.GetUInt32(0x11);
                base2.flags         = this.Reader.GetByte(0x12);
                base2.rest          = this.Reader.GetByte(0x13);
                base2.petinfoid     = this.Reader.GetUInt32(20);
                base2.petlevel      = this.Reader.GetUInt32(0x15);
                base2.petfamilyid   = this.Reader.GetUInt32(0x16);
                base2.displayid     = this.Reader.GetUInt32(0x18);
                base2.tutorialflags = this.Reader.GetUInt32(0x1a);
                Client.Characters.Add(base2);
            }
            Client.User.team = Side.NONE;
            rv.Add((byte)Client.Characters.Count);
            foreach (CharacterBase base3 in Client.Characters)
            {
                Client.User.team = base3.GetSide();
                rv.Add(base3.guid);
                rv.Add(base3.name);
                rv.Add((byte)base3.race);
                rv.Add((byte)base3.class_);
                rv.Add((byte)base3.gender);
                rv.Add(base3.skin);
                rv.Add(base3.face);
                rv.Add(base3.hairstyle);
                rv.Add(base3.haircolor);
                rv.Add(base3.facialhair);
                rv.Add(base3.level);
                rv.Add(base3.zoneid);
                rv.Add(base3.map);
                rv.Add(base3.x);
                rv.Add(base3.y);
                rv.Add(base3.z);
                rv.Add(base3.guildid);
                rv.Add((uint)0);
                rv.Add(base3.rest);
                rv.Add(base3.petinfoid);
                rv.Add(base3.petlevel);
                rv.Add(base3.petfamilyid);
                Console.WriteLine("Guid:{0}", base3.guid);
                rv.Add(new byte[100]);
            }
            this.Reader.Close();
            lock (StaticCore.RealmDbManager)
            {
                MySqlCommand command = new MySqlCommand();
                command.Connection  = StaticCore.RealmDbManager.Connection;
                command.CommandText = "REPLACE INTO realmcharacters (accname, realmid, charcount) VALUES(?accname, ?realmid, ?charcount)";
                command.Parameters.Add("?accname", Client.User.Name);
                command.Parameters.Add("?realmid", StaticCore.RealmID);
                command.Parameters.Add("?charcount", Client.Characters.Count);
                command.ExecuteNonQuery();
            }
            return((byte[])rv);
        }