MySql Execute : index was outside the bounds of the array at C#

09/19/2013 00:49 abdeen#16
Quote:
Originally Posted by shadowman123 View Post
dude the problem is very expectable now ..the error is in eC.Name .. and the problem is that the Database Cant Save this Name as its string type isnt supported in database .. go to entities Table then Design Table .. then check Name column and make sure that its type is varchar , Character Set is utf8 , and Collation is utf8_general_ci then Debug and see
tried as you said and got null error at

Code:
var rdr = new MySqlReader(new MySqlCommand(MySqlCommandType.SELECT).Select("cq_user").Where("name", eC.CharacterName));
:(

Quote:
Originally Posted by 'Emil View Post
Why are you passing ec.CharacterName/Class to the insert, when you already populated the client.entity variables for this? Other than that the code looks fine as far as I can tell, but then again I haven't touched a source in like forever so I can't remember if the name has an encryption on it directly from the packet.



Not necessarily..
so what O.o ?
09/19/2013 00:54 go for it#17
at the first example you said
.Insert("Name", eC.Name)
and it's "Name" not "name" as in this example, that's why you are getting null exception

edit: but still that won't fix the main problem, it would save the name with those weird char(s) inside
09/19/2013 01:02 abdeen#18
Quote:
Originally Posted by shadowman123 View Post
the problem seems from the packet 1001 itself .. make sure you are using the correct method to get the name u Entered it should be like that

Code:
Name = Encoding.Default.GetString(buffer, 24, 16).Replace("\0", "");
Quote:
Originally Posted by go for it View Post
true what's 'emil said at not changing the type at db because it won't solve the wrong name you are getting
and shadowman123 is right aswell about the encoding, it could be anything from cryptography to encoding
i`d tried all methods and same problem ... :(
09/19/2013 01:14 shadowman123#19
why dont u check the client Name in

client.Entity.Name = eC.CharacterName;
check its Value Through Either BreakPoint Or Console and see if its = to the name u entered in Entity Create Page
09/19/2013 02:25 abdeen#20
Quote:
Originally Posted by shadowman123 View Post
why dont u check the client Name in

client.Entity.Name = eC.CharacterName;
check its Value Through Either BreakPoint Or Console and see if its = to the name u entered in Entity Create Page
keep sending me this null error i captured it print screen to show you break point .. Actually i am getting suck of this problem .. isn't going to be fixed ?

at first it was about MySql Execute : index was outside the bounds of the array at C#
now its about it + this null error .. but its came after i edited Name Column in data base so i restored the old one but same null error O.o

[Only registered and activated users can see links. Click Here To Register...]
09/19/2013 03:00 go for it#21
first thing to do, go to your database and get me a picture of it's structure of that table, so i can think of why that query is returning a null
and basically it's because it can't define the rdr object, that could be anything but it's most likely to be you trying to access a non existing column in this database
so make sure that "cq_user" exist with this name with case sensitive
and that "Name" is there with the exact name with case sensitive too !

cool you found the first problem, go back to the project and fix that strings
then you are back to have 1 problem (which i duno what cause it)
09/19/2013 03:20 shadowman123#22
Quote:
Originally Posted by abdeen View Post
keep sending me this null error i captured it print screen to show you break point .. Actually i am getting suck of this problem .. isn't going to be fixed ?

at first it was about MySql Execute : index was outside the bounds of the array at C#
now its about it + this null error .. but its came after i edited Name Column in data base so i restored the old one but same null error O.o

[Only registered and activated users can see links. Click Here To Register...]
Dude you are doing BreakPointing in wrong way ... u just BreakPoint the Variable which u would like to know its value ...

2nd MysqlReader will alawys Be Null no wounder cuz the eC.Name hasnt been saved in database so it will never be able to read smthing that doesnt Exit ...

do this easy Code
Code:
Consile.WriteLine(client.Entity.Name);
and see what u will get btw the Mysql Wrapper is Pathetic and needs Modification as Super Aids said .. the connection stays open when reading , Executing smthing Which is Useless and Wrong ... anyways give me the Result asap
09/19/2013 12:17 _DreadNought_#23
Quote:
Originally Posted by shadowman123 View Post
Dude you are doing BreakPointing in wrong way ... u just BreakPoint the Variable which u would like to know its value ...

2nd MysqlReader will alawys Be Null no wounder cuz the eC.Name hasnt been saved in database so it will never be able to read smthing that doesnt Exit ...

do this easy Code
Code:
Consile.WriteLine(client.Entity.Name);
and see what u will get btw the Mysql Wrapper is Pathetic and needs Modification as Super Aids said .. the connection stays open when reading , Executing smthing Which is Useless and Wrong ... anyways give me the Result asap
The .execute calls whatever problems you mean, the mysql query builder is fine.

Why do console.write? We should be encouraging breakpointing as much as we can people in this community don't know what it is for the most part.
09/19/2013 13:16 abdeen#24
here a latest pic of the problem , null error is fixed now but we returned to the main problem and here a pic of CMD screen !!

[Only registered and activated users can see links. Click Here To Register...]

and still have an error with the character name as you can see in this pic

Note : inserted name was Sexy^Bitch

[Only registered and activated users can see links. Click Here To Register...]

++ entities database table :

Code:
CREATE TABLE `cq_user` (
  `ID` bigint(18) unsigned NOT NULL,
  `Name` varchar(16) NOT NULL,
  `Owner` varchar(45) NOT NULL,
  `Class` tinyint(5) unsigned default '10',
  `Spouse` varchar(16) default 'None',
  `Model` bigint(255) unsigned NOT NULL,
  `Avatar` smallint(12) unsigned NOT NULL,
  `HairStyle` smallint(12) unsigned NOT NULL default '430',
  `Level` tinyint(5) unsigned default '1',
  `Money` bigint(18) unsigned default '0',
  `ConquerPoints` bigint(18) unsigned default '0',
  `PKPoints` smallint(12) unsigned default '0',
  `Hitpoints` mediumint(16) unsigned default '93',
  `Mana` mediumint(16) unsigned default '0',
  `Strenght` smallint(12) unsigned default '1',
  `Agility` smallint(12) unsigned default '1',
  `Vitality` smallint(12) unsigned default '1',
  `Spirit` smallint(12) unsigned default '0',
  `StatPoints` smallint(12) unsigned default '0',
  `Experience` bigint(255) unsigned default '0',
  `VirtuePoints` bigint(255) unsigned default '0',
  `Reborn` tinyint(2) unsigned default '0',
  `Map` smallint(12) unsigned default '1002',
  `X` smallint(12) unsigned default '430',
  `Y` smallint(12) unsigned default '380',
  `PreviousMapID` smallint(12) unsigned default '1010',
  `PrevX` mediumint(10) default '0',
  `PrevY` mediumint(10) default '0',
  PRIMARY KEY  (`ID`,`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
09/19/2013 15:08 shadowman123#25
Quote:
Originally Posted by _DreadNought_ View Post
The .execute calls whatever problems you mean, the mysql query builder is fine.

Why do console.write? We should be encouraging breakpointing as much as we can people in this community don't know what it is for the most part.
to be Honest i h8 BreakPointing and i prefer using Try and catch with showing the Error in console .. cuz its Faster than doing breakpoints in giving results

Quote:
Originally Posted by abdeen View Post
Note : inserted name was Sexy^Bitch
[Only registered and activated users can see links. Click Here To Register...]
we made good progress till now cuz we have known that the problem is in eC.Name ..
09/19/2013 15:18 abdeen#26
Quote:
Originally Posted by shadowman123 View Post
to be Honest i h8 BreakPointing and i prefer using Try and catch with showing the Error in console .. cuz its Faster than doing breakpoints in giving results



we made good progress till now cuz we have known that the problem is in eC.Name ..
well am very happy now , we have known the problem is in eC.Name may i say ( lwlwlwlwlwllwlwlwywyyyyyy ) jk :)

any suggestion about how to fix this problem ?

any new way for encrypt or decrypt the character name ? you see what i got when i inserted Sexy^Bitch as a character name O.o

O my lord i am getting sick of this problem ...
09/19/2013 16:25 shadowman123#27
PacketHandler.cs / Check EntityCreate Packet 1001 .. then use Console.WriteLine to check the value of the Entered Name and tell me the updates
09/19/2013 17:03 abdeen#28
Quote:
Originally Posted by shadowman123 View Post
PacketHandler.cs / Check EntityCreate Packet 1001 .. then use Console.WriteLine to check the value of the Entered Name and tell me the updates
PacketHandler.cs

Code:
#region Create Character Packet 1001
                    case 1001:
                        {
                                EnitityCreate EC = new EnitityCreate(true);
                                EC.Deserialize(packet);
                                string Message = "";
                                Boolean Created = Database.UserTable.CreateEntity(EC, client, ref Message);
                                client.Send(new GameServer.Network.GamePacket.MessagePacket(Message, "ALLUSERS", System.Drawing.Color.Orange, GameServer.Network.GamePacket.MessagePacket.Dialog));
                                if (Created)
                                {
                                    client.Send(Packets.SendMsg(client.Entity.ID, "SYSTEM", "ALLUSERS", "ANSWER_OK", 0x834));
                                    Console.WriteLine(client.Account.Username + " Sucesfully Created a new Character " + EC.CharacterName);
                                    client.JustCreated = true;
                                }
                                else
                                {
                                    client.Disconnect();
                                    return;
                                }
                            break;
                        }
                    #endregion
EnitityCreate

Code:
public class EnitityCreate : Interfaces.IPacket
    {
        byte[] Buffer;
        public EnitityCreate(bool Create)
        {
            if (Create)
            {
                this.Buffer = new byte[60];
                WriteUInt16(60, this.Buffer, 0);
                WriteUInt16(0x3E9, this.Buffer, 2);
            }
        }
        public string AccountName
        {
            get
            {
                return Encoding.ASCII.GetString(Buffer, 4, 16);
            }
            set
            {
                Network.Writer.WriteString(value, 4, Buffer);
            }
        }
        public string AccountPassword
        {
            get
            {
                return Encoding.ASCII.GetString(Buffer, 36, 16);
            }
            set
            {
                Network.Writer.WriteString(value, 36, Buffer);
            }
        }
        public string CharacterName
        {
            get
            {
                return Encoding.ASCII.GetString(Buffer, 20, 16);
            }
            set
            {
                Network.Writer.WriteString(value, 20, Buffer);
            }
        }
        public ushort CharacterModel
        {
            get
            {
                return BitConverter.ToUInt16(Buffer, 52);
            }
            set
            {
                Network.Writer.WriteUInt16(value, 52, Buffer);
            }
        }
        public ushort CharacterClass
        {
            get
            {
                return BitConverter.ToUInt16(Buffer, 54);
            }
            set
            {
                Network.Writer.WriteUInt16(value, 54, Buffer);
            }
        }
        public uint AccountUniqueID
        {
            get
            {
                return BitConverter.ToUInt32(Buffer, 56);
            }
            set
            {
                Network.Writer.WriteUInt32(value, 56, Buffer);
            }
        }
        public byte[] Serialize()
        {
            return this.Buffer;
        }
        public void Deserialize(byte[] buffer)
        {
            Buffer = buffer;
        }
        public byte[] ToArray()
        {
            return Buffer;
        }
        public void Send(Client.GameState client)
        {
            client.Send(Buffer);
        }
        public static void ZeroFill(byte[] Buffer, ushort Offset, ushort Count)
        {
            for (ushort i = 0; i < Count; i++)
                Buffer[i + Offset] = 0x00;
        }
        public static void WriteStringWithLength(string Arg, byte[] Buffer, ushort Offset)
        {
            Buffer[Offset] = (byte)Arg.Length;
            Offset++;
            ushort i = 0;
            while (i < Arg.Length)
            {
                Buffer[(ushort)(i + Offset)] = (byte)Arg[i];
                i = (ushort)(i + 1);
            }
        }
        public static void WriteString(string Arg, byte[] Buffer, ushort Offset)
        {
            ushort i = 0;
            while (i < Arg.Length)
            {
                Buffer[(ushort)(i + Offset)] = (byte)Arg[i];
                i = (ushort)(i + 1);
            }
        }
        public static void WriteUInt16(ushort Arg, byte[] Buffer, ushort Offset)
        {
            Buffer[Offset] = (byte)(Arg);
            Buffer[Offset + 1] = (byte)(Arg >> 8);
        }
        public static void WriteUInt32(uint Arg, byte[] Buffer, ushort Offset)
        {
            Buffer[Offset] = (byte)(Arg);
            Buffer[Offset + 1] = (byte)(Arg >> 8);
            Buffer[Offset + 2] = (byte)(Arg >> 16);
            Buffer[Offset + 3] = (byte)(Arg >> 24);
        }
    }
Database >> UserTable >> CreateEntity

Code:
public static bool CreateEntity(Network.GamePackets.EnitityCreate eC, Client.GameState client, ref string message)
        {
            try
            {
                var rdr = new MySqlReader(new MySqlCommand(MySqlCommandType.SELECT).Select("cq_user").Where("Name", eC.CharacterName));
                if (rdr.Read())
                {
                    rdr.Close();
                    message = "The chosen name is already in use.";
                    return false;
                }
                rdr.Close();
                client.Entity = new Entity(EntityFlag.Player, false);
                client.Entity.Name = eC.CharacterName;
                Console.WriteLine(client.Entity.Name);
                DataHolder.GetStats((byte)eC.CharacterClass, 1, client);
                client.Entity.ID = Program.EntityUID.Next;
                new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("EntityID", client.Entity.ID).Where("Server", ServerBase.Constants.ServerName).Execute();
                //client.CalculateStatBonus();
                //client.CalculateHPBonus();
                client.Entity.Hitpoints = client.Entity.MaxHitpoints;
                client.Entity.Mana = (ushort)(client.Entity.Spirit * 5);
                client.Entity.Class = (byte)eC.CharacterClass;
                client.Entity.Model = eC.CharacterModel;
                if (eC.CharacterModel == 1003 && eC.CharacterClass == 10 || eC.CharacterModel == 1003 && eC.CharacterClass == 20 || eC.CharacterModel == 1003 && eC.CharacterClass == 40 || eC.CharacterModel == 1003 && eC.CharacterClass == 100 || eC.CharacterModel == 1004 && eC.CharacterClass == 10 || eC.CharacterModel == 1004 && eC.CharacterClass == 20 || eC.CharacterModel == 1004 && eC.CharacterClass == 40 || eC.CharacterModel == 1004 && eC.CharacterClass == 100)
                {
                    client.Entity.Avatar = (ushort)ServerBase.Kernel.Random.Next(1, 50);
                }
                else
                {
                    client.Entity.Avatar = (ushort)ServerBase.Kernel.Random.Next(201, 250);
                }
                byte Color = (byte)ServerBase.Kernel.Random.Next(4, 8);

                client.Entity.HairStyle = (ushort)(Color * 100 + 10 + (byte)ServerBase.Kernel.Random.Next(4, 9));
                client.Account.EntityID = client.Entity.ID;
                client.Account.Save();
                Console.WriteLine("cq_user" +
                    "Name" + eC.CharacterName
                     + "Owner" + client.Account.Username
                     + "Class" + eC.CharacterClass
                     + "ID" + client.Entity.ID
                     + "Hitpoints" + client.Entity.Hitpoints
                     + "Mana" + client.Entity.Mana
                     + "Model" + client.Entity.Model
                     + "Avatar" + client.Entity.Avatar
                     + "HairStyle" + client.Entity.HairStyle);
                MySqlCommand cmd = new MySqlCommand(MySqlCommandType.INSERT);
                cmd.Insert("cq_user")
                    .Insert("Name", client.Entity.Name)
                    .Insert("Owner", client.Account.Username)
                    .Insert("Class", client.Entity.Class)
                    .Insert("ID", client.Entity.ID)
                    .Insert("Hitpoints", client.Entity.Hitpoints)
                    .Insert("Mana", client.Entity.Mana)
                    .Insert("Model", client.Entity.Model)
                    .Insert("Avatar", client.Entity.Avatar)
                    .Insert("HairStyle", client.Entity.HairStyle)
                .Insert("Strenght", client.Entity.Strenght)
                .Insert("Agility", client.Entity.Agility)
                .Insert("Vitality", client.Entity.Vitality)
                .Insert("Spirit", client.Entity.Spirit);
                cmd.Execute();
                client.Account.LoginState = AccountTable.AccountLoginState.Login;
                new MySqlCommand(MySqlCommandType.UPDATE)
                    .Update("accounts")
                    .Set("LoginState", (byte)client.Account.LoginState)
                    .Where("EntityID", client.Entity.ID)
                    .Execute();
                message = "ANSWER_OK";
            }
            catch (Exception cc) { GameServer.ServerBase.ErrorHandler.Catch(cc); message = "A problem when we registering your character , please try again later !!"; return false; }
            return true;
        }

cq_user table

Code:
CREATE TABLE `cq_user` (
  `ID` bigint(18) unsigned NOT NULL,
  `Name` varchar(16) NOT NULL,
  `Owner` varchar(45) NOT NULL,
  `Class` tinyint(5) unsigned default '10',
  `Spouse` varchar(16) default 'None',
  `Model` bigint(255) unsigned NOT NULL,
  `Avatar` smallint(12) unsigned NOT NULL,
  `HairStyle` smallint(12) unsigned NOT NULL default '430',
  `Level` tinyint(5) unsigned default '1',
  `Money` bigint(18) unsigned default '0',
  `ConquerPoints` bigint(18) unsigned default '0',
  `PKPoints` smallint(12) unsigned default '0',
  `Hitpoints` mediumint(16) unsigned default '93',
  `Mana` mediumint(16) unsigned default '0',
  `Strenght` smallint(12) unsigned default '1',
  `Agility` smallint(12) unsigned default '1',
  `Vitality` smallint(12) unsigned default '1',
  `Spirit` smallint(12) unsigned default '0',
  `StatPoints` smallint(12) unsigned default '0',
  `Experience` bigint(255) unsigned default '0',
  `VirtuePoints` bigint(255) unsigned default '0',
  `Reborn` tinyint(2) unsigned default '0',
  `Map` smallint(12) unsigned default '1002',
  `X` smallint(12) unsigned default '430',
  `Y` smallint(12) unsigned default '380',
  `PreviousMapID` smallint(12) unsigned default '1010',
  `PrevX` mediumint(10) default '0',
  `PrevY` mediumint(10) default '0',
  PRIMARY KEY  (`ID`,`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

so here i provided all info .. then what ?
09/19/2013 20:14 _DreadNought_#29
Quote:
Originally Posted by shadowman123 View Post
to be Honest i h8 BreakPointing and i prefer using Try and catch with showing the Error in console .. cuz its Faster than doing breakpoints in giving results



we made good progress till now cuz we have known that the problem is in eC.Name ..
Regardless, what about bugs that dont throw errors? Would you just put out a ton of console.write?

I'm thinking you don't know how to step/use breakpoints because otherwise theres no way you would be bashing them, they're a developers best friend.
09/19/2013 20:27 abdeen#30
even if i use this method

Code:
        public void Deserialize(byte[] buffer)
        {
            try
            {
                Console.WriteLine("create entity buffer length : " + buffer.Length);
                if (buffer.Length == 60)
                {
                    MemoryStream MS = new MemoryStream(buffer);
                    BinaryReader BR = new BinaryReader(MS);
                    charname = Encoding.ASCII.GetString(BR.ReadBytes(16));
                    charname = charname.Replace("\0", "");
                    Console.WriteLine(" Charr name : " + CharacterName + "   Class    " + CharacterClass + "   Model  " + CharacterModel);
                    BR.Close();
                    MS.Close();
                }
                Buffer = buffer;
            }
            catch (Exception cc) { GameServer.ServerBase.ErrorHandler.Catch(cc); }
        }
and i inserted the name is " aassdd " just for testing ...

i got it ... something i can't type my self ..

[Only registered and activated users can see links. Click Here To Register...]

does that means none know how to fix this ??

omg i can't believe that..

================================================

hey guys am still trying and keep trying but even if i use this method too :

Code:
                private byte[] Data;
        private Client.GameState client;

        public EnitityCreate(byte[] data, Client.GameState C)
        {
            Data = data;
            client = C;

            try
            {
                string Account = "";
                for (sbyte i = 0x04; i < 0x14; i++)
                    if (Data[i] != 0x00)
                        Account += (char)Data[i];

                string Name = "";
                for (sbyte i = 0x14; i < 0x24; i++)
                    if (Data[i] != 0x00)
                        Name += (char)Data[i];

                uint Look = (ushort)((Data[0x35] << 8) + Data[0x34]);
                ushort Job = (ushort)((Data[0x37] << 8) + Data[0x36]);

                ushort Avatar = 67;

                if (Look == 2001 || Look == 2002)
                    Avatar = 201;
                else
                    Avatar = 67;
                    client.Send(Packets.SendMsg(client.HashUID, "SYSTEM", "ALLUSERS", "ANSWER_OK", 0x834));
                    bool Success = Database.UserTable.CreateCharacter(Name, Job, Look, Avatar, client);
                    if (!Success)
                    {
                        client.Send(Packets.SendMsg(client.HashUID, "SYSTEM", "ALLUSERS", "Creation of Account isn't Success !!", 0x834));
                        client.Disconnect();
                        return;
                    }
                    Console.WriteLine("New character: " + Name);
            }
            catch (Exception cc) { GameServer.ServerBase.ErrorHandler.Catch(cc); }
        }
Code:
        internal static bool CreateCharacter(string Name, ushort Job, uint Look, ushort Avatar, Client.GameState client)
        {
            if (Name != null && Job > 0 && Look > 0 && Avatar > 0 && client != null)
            {
                Console.WriteLine("Char Name : " + Name + " Char Model : " + Look + " Char Avatar : " + Avatar + " Client : " + client);
                return true;
            }
            return false;
        }
i get this :

[Only registered and activated users can see links. Click Here To Register...]

bad name , model and as i think bad avatar values ...

O.o