Esempio n. 1
0
 public int Add(CString pString)
 {
     CString newString = new CString();
     newString.Write(pString);
     _bufferList[this._id] = newString;
     int listId = this._id;
     this._id++;
     return listId;
 }
Esempio n. 2
0
 public int Add(string pStr)
 {
     CString newString;
     if (pStr == null)
         newString = new CString();
     else
     {
         newString = new CString();
         newString.Write(pStr);
     }
     _bufferList[this._id] = newString;
     int listId = this._id;
     this._id++;
     return listId;
 }
Esempio n. 3
0
        public void Replace(int pIndex, string pString)
        {
            CString str = (CString)_bufferList[pIndex];
            if (str == null)
                return;
            //delete str;

            str = new CString();
            str.Write(pString);
            this._bufferList[pIndex] = str;
        }
Esempio n. 4
0
        public void Load(string pInput, char pSep)
        {
            CString newString = new CString();
            //this.clear();
            newString.Write(pInput);

            string[] lines = newString.Text.Split(pSep);
            foreach (string line in lines)
            {
                this.Add(line);
                //line = strtok(null, pSep);
            }
        }
        /// <summary>
        /// Handle Received Data
        /// </summary>
        protected override void HandleData(CString Packet)
        {
            // Player not logged in
            if (!LoggedIn)
                HandleLogin (Packet.ReadString ('\n'));

            // Parse Packets
            while (Packet.BytesLeft > 0) {
                // Grab Single Packet
                CString CurPacket = Packet.ReadString ('\n');

                // Read Packet Type
                int PacketId = CurPacket.ReadGUByte1 ();

                // Call Packet Callback
                //RemoteControl.CallCallBack(PacketId, (CString)CurPacket.DeepClone());

                // Run Internal Packet Function
                switch ((PacketIn)PacketId) {
                //case PacketIn.NPCWEAPONADD: // Add Class to List
                //	{
                //String className = CurPacket.ReadString().Text;
                //if (RemoteControl.ClassList.IndexOf(className) == -1)
                //	RemoteControl.ClassList.Add(className);
                //		break;
                //	}

                //case PacketIn.NEWWORLDTIME: // Remove Class from List
                //RemoteControl.ClassList.Remove(CurPacket.ReadString().Text);
                //	break;

                // Retrieve Class
                case PacketIn.NC_CLASSGET:
                    {
                        String Name = CurPacket.ReadString ().Text;
                        ServerClass Class = Server.FindClass (Name);
                        if (Class != null)
                            SendPacket (new CString () + (byte)PacketOut.NC_WEAPONGET + (byte)Class.Name.Length + Class.Name + Class.Script.Replace ('\n', '\xa7'));
                        else
                            Server.SendNCChat (Account + " prob: script " + Name + " doesn't exist", null);
                        break;
                    }

                // Set Class
                case PacketIn.NC_CLASSADD:
                    {
                        String ClassName = CurPacket.ReadChars (CurPacket.ReadGUByte1 ());
                        String ClassScript = CurPacket.ReadString ().Untokenize().Text;
                        Console.WriteLine(" prob: Class " + ClassName + " Script: " + ClassScript);
                        int res = Server.SetClass (ClassName, ClassScript, true);
                        if (res >= 0)
                            Server.SendNCChat ("Script " + ClassName + " " + (res == 1 ? "added" : "updated") + " by " + this.Account);
                        break;
                    }

                // Delete Class
                case PacketIn.NC_CLASSDELETE:
                    {
                        String ClassName = CurPacket.ReadString ().Text;
                        if (Server.DeleteClass (ClassName))
                            Server.SendNCChat ("Script " + ClassName + " deleted by " + this.Account);
                        else
                            Server.SendNCChat (Account + " prob: script " + ClassName + " doesn't exist");
                        break;
                    }

                // Retrieve Weapon List
                case PacketIn.NC_WEAPONLISTGET:
                    {
                        CString Out = new CString () + (byte)PacketOut.NC_WEAPONLISTGET;
                        foreach (KeyValuePair<string, ServerWeapon> weapon in Server.WeaponList) {
                            Out.WriteGByte1 ((sbyte)weapon.Key.Length);
                            Out.Write (weapon.Key);
                        }
                        SendPacket (Out);
                        break;
                    }

                case PacketIn.NC_LEVELLISTGET:
                    {
                        CString Out = new CString () + (byte)PacketOut.NC_LEVELLIST;
                        foreach (KeyValuePair<string, GraalLevel> level in Server.LevelList) {
                            Out.WriteGByte1 ((sbyte)level.Key.Length);
                            Out.Write (level.Key);
                        }
                        SendPacket (Out);
                        break;
                    }

                // Retrieve Weapon
                case PacketIn.NC_WEAPONGET:
                    {
                        String Name = CurPacket.ReadString ().Text;
                        ServerWeapon Weapon = Server.FindWeapon (Name);
                        if (Weapon != null)
                            SendPacket (new CString () + (byte)PacketOut.NC_WEAPONGET + (byte)Weapon.Name.Length + Weapon.Name + (byte)Weapon.Image.Length + Weapon.Image + Weapon.Script.Replace ('\n', '\xa7'));
                        else
                            Server.SendNCChat (Account + " prob: weapon " + Name + " doesn't exist", null);
                        break;
                    }

                // Set Weapon
                case PacketIn.NC_WEAPONADD:
                    {
                        String WeaponName = CurPacket.ReadChars (CurPacket.ReadGUByte1 ());
                        String WeaponImage = CurPacket.ReadChars (CurPacket.ReadGUByte1 ());
                        String WeaponScript = CurPacket.ReadString ().Text;
                        int res = Server.SetWeapon (this.Server.GSConn, WeaponName, WeaponImage, WeaponScript, true);
                        if (res >= 0)
                            Server.SendNCChat ("Weapon/GUI-script " + WeaponName + " " + (res == 1 ? "added" : "updated") + " by " + this.Account);
                        break;
                    }

                // Delete Weapon
                case PacketIn.NC_WEAPONDELETE:
                    {
                        String WeaponName = CurPacket.ReadString ().Text;
                        if (Server.DeleteWeapon (WeaponName))
                            Server.SendNCChat ("Weapon " + WeaponName + " deleted by " + this.Account);
                        else
                            Server.SendNCChat (Account + " prob: weapon " + WeaponName + " doesn't exist");
                        break;
                    }
                /*
                case PacketIn.NC_CHAT:
                    break;
                */
                default:
                    System.Console.WriteLine ("CLIENTNC -> Packet [" + PacketId + "]: " + CurPacket.Text);
                    break;
                }
            }
        }
Esempio n. 6
0
        public CString ReadChars2(uint pCount)
        {
            Byte[] data = new byte[pCount];
            Read(data);
            CString data2 = new CString();

            data2.Write(Encoding.Default.GetString(data, 0, data.Length));

            return data2;
        }