public override void ReceivedPM(short PlayerId, CString Message) { GraalPlayer PMPlayer = this.PlayerManager.FindPlayer(PlayerId); if (PMPlayer != null) this.ReceivedPM(PMPlayer, Message); else this.form.WriteText("Something went wrong. PMPlayer is null."); }
public int Add(CString pString) { CString newString = new CString(); newString.Write(pString); _bufferList[this._id] = newString; int listId = this._id; this._id++; return listId; }
public Sprite(int pSprite, CString pImage, int pX, int pY, int pW, int pH) { _sprite = pSprite; _file = pImage; _x = pX; _y = pY; _w = pW; _h = pH; }
public void ReceivedPM(Player Player, CString Message) { this.form = Abstraction.GetInstance(); this.form.WriteText(" -!- Received PM from " + Player.Account.ToString() + "!\n"); PMWindowManager = PMWindowList.GetInstance(); PMWindow PM = PMWindowManager.AddPMWindow(Player.Id); if (PM != null) { PM.SetMessage(Message); } }
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; }
/// <summary> /// Set Properties /// </summary> internal void SetMessage(CString Packet) { if (this.richTextBox1.InvokeRequired) { SetTextCallback d = new SetTextCallback(SetMessage); this.Invoke(d, new object[] { Packet }); } else { //this.richTextBox1.AppendText(text); this.LastMessage = Packet; //this.Enabled = true; //this.richTextBox1.Enabled = true; this.richTextBox1.AppendText(this.PMPlayer.Nickname + " says:\r\n"+ CString.untokenize(this.LastMessage.Text)+"\r\n"); this.Show(); } }
private bool LoadGraal(CString levelData, string fileVersion) { return false; }
public bool LoadTypeDefinitions(CString pFileName) { CStringList typeDefs = new CStringList(); if (!typeDefs.Load(pFileName.Text)) return false; if (typeDefs.Count < 1) return false; foreach (CString typeDefLine in typeDefs) { for (var i = 0; i < typeDefLine.Text.Length; i++) { //Console.WriteLine("TileId: " + i.ToString() + " - TileType: " + Enum.GetName(typeof(TileType), typeDefLine.ReadByte()).ToString()); this.TileTypeDefinitions.Add(i, typeDefLine.ReadByte()); } } return true; }
public bool Load(CString pFileName) { CStringList levelData = new CStringList(); if (!levelData.Load(pFileName.Text)) return false; if (levelData.Count < 1) return false; // Grab file version. string fileVersion = levelData.Get(0).ReadChars(8); // Determine the level type. int v = -1; if (fileVersion == "GLEVNW01") v = 0; else if (fileVersion == "GR-V1.03" || fileVersion == "GR-V1.02" || fileVersion == "GR-V1.01") v = 1; else if (fileVersion == "Z3-V1.04" || fileVersion == "Z3-V1.03") v = 2; // Not a level. if (v == -1) return false; // Load the correct level. if (v == 0) return this.LoadNW(levelData); if (v == 1) return this.LoadGraal(levelData.Join("\n"), fileVersion); if (v == 2) return this.LoadZelda(levelData.Join("\n"), fileVersion); return false; }
/// <summary> /// Send Packet to GServer /// </summary> public void SendGSPacket(CString Packet) { GSConn.SendPacket (Packet); }
/// <summary> /// Handle Received Data /// </summary> protected override void HandleData(CString Packet) { 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) { // Packet 6 - Set Active Level & Clear case PacketIn.LEVELNAME: ActiveLevel = Server.FindLevel (CurPacket.ReadString ().Text); Console.WriteLine (ActiveLevel.Name); //ActiveLevel.Clear(); break; // Paceket 1 - Level Links case PacketIn.LEVELLINKS: break; // Packet 3 - Level NPC Props case PacketIn.LEVELNPCPROPS: { int npcId = CurPacket.ReadGByte3 (); //Console.WriteLine("npc-id("+npcId.ToString()+")"); if (ActiveLevel != null) { GraalLevelNPC test = ActiveLevel.GetNPC (this.Server.GSConn, npcId); test.npcserver = true; test.SetProps (CurPacket); /* foreach (NCConnection nc in Server.NCList) { nc.SendPacket(new CString() + (byte)NCConnection.PacketOut.NC_NPCADD + (int)test.Id + (byte)50 + (byte)test.Nickname.Length + test.Nickname + (byte)51 + (byte)("OBJECT".Length) + "OBJECT" + (byte)52 + (byte)test.Level.Name.Length + test.Level.Name); } */ this.Server.Compiler.CompileAdd (test); } break; } // Packet 5 - Level Signs case PacketIn.LEVELSIGNS: break; // Packet 39 - Level Mod Time case PacketIn.LEVELMODTIME: if (ActiveLevel != null) ActiveLevel.SetModTime (CurPacket.ReadGUByte5 ()); break; // Packet 150 - Delete Level NPC case PacketIn.LEVELNPCDELETE: Server.FindLevel (CurPacket.ReadChars (CurPacket.ReadGUByte1 ())).DeleteNPC (CurPacket.ReadGByte3 ()); break; // Packet 156 - Set Active Level case PacketIn.LEVELSETACTIVE: ActiveLevel = Server.FindLevel (CurPacket.ReadString ().Text); break; // Add Player & Set Props case PacketIn.OTHERPLPROPS: { Players.Player Player = (Players.Player)Server.PlayerManager.AddPlayer (CurPacket.ReadGByte2 (), this); if (Player != null) { Player.SetProps (CurPacket); } break; } case PacketIn.PLFLAGSET: { Players.Player Player = (Players.Player)Server.PlayerManager.AddPlayer (CurPacket.ReadGByte2 ()); String FlagName = CurPacket.ReadString ('=').Text; String FlagValue = CurPacket.ReadString ().Text; if (Player != null) Player.Flags [FlagName] = FlagValue; break; } case PacketIn.PLAYERPROPS: if (NCPlayer == null) NCPlayer = (Players.Player)Server.PlayerManager.AddPlayer (0); NCPlayer.SetProps (CurPacket); break; // Add weapon to list case PacketIn.NPCWEAPONADD: { String WeaponName = CurPacket.ReadChars (CurPacket.ReadGUByte1 ()); String WeaponImage = CurPacket.ReadChars (CurPacket.ReadGUByte1 ()); String WeaponScript = CurPacket.ReadString ().Text; Server.SetWeapon (this, WeaponName, WeaponImage, WeaponScript, false); /* foreach (Players.Player p in this.Server.PlayerManager) { this.Server.SendGSPacket (new CString () + (byte)GServerConnection.PacketOut.NCQUERY + (byte)GServerConnection.NCREQ.PLGETWEPS + (short)p.Id); } */ break; } // Add/Remove weapon from Player case PacketIn.PLWEAPONMNG: { Players.Player Player = (Players.Player)Server.PlayerManager.AddPlayer (CurPacket.ReadGByte2 ()); if (Player != null) { bool addWeapon = (CurPacket.ReadGByte1 () > 0); String name = CurPacket.ReadString ().Text; if (addWeapon) Player.AddWeapon (name); else Player.DeleteWeapon (name, false); } break; } case PacketIn.PLWEAPONSSET: { Players.Player Player = (Players.Player)Server.PlayerManager.AddPlayer (CurPacket.ReadGByte2 ()); if (Player != null) { while (CurPacket.BytesLeft > 0) Player.AddWeapon (CurPacket.ReadChars (CurPacket.ReadGUByte1 ())); } break; } case PacketIn.NEWWORLDTIME: // Remove Class from List Server.NWTime = CurPacket.ReadGByte4 (); //RemoteControl.ClassList.Remove(CurPacket.ReadString().Text); break; // Private Message case PacketIn.PRIVATEMESSAGE: short PlayerId = CurPacket.ReadGByte2 (); CString Message = CurPacket.ReadString (); Server.SendPM (PlayerId, Server.NCMsg, true); break; case PacketIn.TRIGGERACTION: short _pid = CurPacket.ReadGByte2 (); int _npcId = (int)CurPacket.readGUInt (); float x = (float)CurPacket.readGUChar () / 2.0f; float y = (float)CurPacket.readGUChar () / 2.0f; string action = CurPacket.ReadString (',').ToString ().Trim (); string[] _params = CurPacket.ReadString ().ToString ().Split (','); Console.Write ("Call npcid(" + _npcId.ToString () + ") onAction" + action + "(_params); _params: "); foreach (string p in _params) Console.Write (p + ", "); Console.WriteLine (); if (_npcId != 0) { GraalLevelNPC tmpNpc = this.Server.PlayerManager.FindPlayer (_pid).Level.GetNPC (_npcId); if (tmpNpc == null) Console.WriteLine ("npc cannot be found! :'("); if (tmpNpc != null) tmpNpc.Call ("onAction" + action, new object[] { this.Server.PlayerManager.FindPlayer (_pid), _params }); } else { this.Server.PlayerManager.FindPlayer (_pid).CallNPCs ("onAction" + action, new object[] { this.Server.PlayerManager.FindPlayer (_pid), _params } ); this.Server.PlayerManager.FindPlayer (_pid).Level.CallNPCs ("onAction" + action, new object[] { this.Server.PlayerManager.FindPlayer (_pid), _params } ); } break; case PacketIn.NC_CONTROL: System.Console.Write ("GSCONN -> Packet [" + (PacketIn)PacketId + "]: "); Server.SendGSPacket (new CString () + (byte)PacketOut.GETWEAPONS); Server.SendGSPacket (new CString () + (byte)PacketOut.GETLEVELS); int PacketId2 = CurPacket.ReadGUByte1 (); switch ((NCI)PacketId2) { case NCI.PLAYERWEAPONS: // 0 { Players.Player Player = (Players.Player)Server.PlayerManager.AddPlayer (CurPacket.ReadGByte2 ()); if (Player != null) { Console.WriteLine (Player.Account); CString weapons = CurPacket.Untokenize (); string[] weaponsarr = weapons.ToString ().Split ('\n'); foreach (string tmpWeap in weaponsarr) { //string tmpWeap = CurPacket.ReadChars(CurPacket.ReadGUByte1()); Console.WriteLine ("Weapon: " + tmpWeap); if (Player.FindWeapon (tmpWeap) == null) { Console.WriteLine ("Not Found on player"); Common.Scripting.ServerWeapon tmpWeap2 = this.Server.FindWeapon (tmpWeap); if (tmpWeap2 != null) { Console.WriteLine ("Adding"); Player.AddWeapon (tmpWeap2); } else Console.WriteLine ("Weapon not found in system. :'("); } } } break; } case NCI.PLAYERWEAPONADD: System.Console.WriteLine (" ADDWEAPON"); Players.Player _Player = (Players.Player)Server.PlayerManager.AddPlayer (CurPacket.ReadGByte2 ()); if (_Player != null) { System.Console.Write ("Player: " + _Player.Account); bool addWeapon = (CurPacket.ReadGByte1 () > 0); String name = CurPacket.ReadString ().Text; System.Console.WriteLine (" Name: " + name); Common.Scripting.ServerWeapon tmpWp = this.Server.FindWeapon (name); if (addWeapon) _Player.AddWeapon (tmpWp); else _Player.DeleteWeapon (name, false); } break; default: System.Console.WriteLine ("[" + PacketId2 + "]: " + CurPacket.ReadString ().Text); break; } break; default: System.Console.WriteLine ("GSCONN -> Packet [" + (PacketIn)PacketId + "]: " + CurPacket.ReadString ().Text); break; } } }
public void SendMessage(CString message) { this.Server = Framework.GetInstance(); this.Server.SendPM(this._id, CString.tokenize(message.Text), true); Gtk.Application.Invoke(delegate { Abstraction mw = Abstraction.GetInstance(); this.WriteText("(" + mw.NCPlayer.Nickname + "(You)): " + message.Text); message = null; } ); }
public override void ReceivedPM(string PlayerId, CString Message) { GraalPlayer PMPlayer = this.PlayerManager.FindPlayer(PlayerId); this.ReceivedPM(PMPlayer, Message); }
/* /// <summary> /// Send Colors /// </summary> internal void SendColors() { this.SendProp(Properties.PLCOLORS); } /// <summary> /// Send Flag to Framework /// </summary> internal void SendFlag(String FlagName, String FlagValue) { // fix packet for flag //Server.SendGSPacket(new CString() + (byte)GServerConnection.PacketOut.NC_NPCGET + (byte)GServerConnection.NCREQ.PLSETFLAG + (short)Id + FlagName + "=" + FlagValue); } /// <summary> /// Send Prop to GServer /// </summary> internal void SendProp(Properties PropId) { //Server.SendGSPacket(new CString() + (byte)GServerConnection.PacketOut.NC_NPCGET + (byte)GServerConnection.NCREQ.PLSETPROPS + (short)this.Id + (byte)PropId + GetProp(PropId)); } /// <summary> /// Set Player Guild /// </summary> internal void SetGuild(string GuildName) { int guildStart, guildEnd; if ((guildStart = Nickname.IndexOf('(')) >= 0) { if ((guildEnd = Nickname.IndexOf(')', guildStart)) >= 0) Nickname = Nickname.Substring(0, guildStart).TrimEnd(); } if (GuildName != String.Empty) Nickname += " (" + GuildName + ")"; } /// <summary> /// Set Player Nickname /// </summary> /// <param name="Nickname"></param> internal void SetNick(string Nickname) { // Set Nickname this.Nickname = Nickname; this.Guild = ""; // Parse Guild int len = Nickname.LastIndexOf('('); if (len != -1) { int len2 = Nickname.LastIndexOf(')'); if (len2 > len) this.Guild = Nickname.Substring(len + 1, len2 - len - 1); } this.form.AddPlayer(this.account, this.Nickname); } */ /// <summary> /// Set Properties /// </summary> public void SetProps(CString Packet) { this.form = Abstraction.GetInstance(); bool moved = false; while (Packet.BytesLeft > 0) { Int32 PropId = Packet.ReadGUByte1(); //this.form.AddPlayer(this.Account, this.Account); switch ((Properties)PropId) { case Properties.NICKNAME: // 0 { this.SetNick(Packet.ReadChars(Packet.ReadGUByte1())); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Nickname + ""); break; } case Properties.MAXPOWER: // 1 this.FullHearts = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.FullHearts + "\r\n"); break; case Properties.CURPOWER: // 2 this.Hearts = (double)Packet.ReadGUByte1() / 2; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Hearts + "\r\n"); break; case Properties.RUPEESCOUNT: // 3 this.Gralats = (int)Packet.ReadGUByte3(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Gralats + ""); break; case Properties.ARROWSCOUNT: // 4 this.Arrows = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Arrows + "\r\n"); break; case Properties.BOMBSCOUNT: // 5 this.Bombs = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Bombs + "\r\n"); break; case Properties.GLOVEPOWER: // 6 this.GlovePower = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.glovepower + "\r\n"); break; case Properties.BOMBPOWER: // 7 this.BombPower = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.BombPower + "\r\n"); break; case Properties.SWORDPOWER: // 8 { Int32 sp = Packet.ReadGUByte1(); if (sp > 4) { sp -= 30; Int32 len = Packet.ReadGUByte1(); if (len > 0) this.SwordImage = Packet.ReadChars(len); } else this.SwordImage = "sword" + sp + ".png"; this.SwordPower = sp; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.swordpower + "\r\n"); break; } case Properties.SHIELDPOWER: // 9 { Int32 sp = Packet.ReadGUByte1(); if (sp > 3) { sp -= 10; if (sp < 0) break; Int32 len = Packet.ReadGUByte1(); if (len > 0) this.ShieldImage = Packet.ReadChars(len); } else this.ShieldImage = "shield" + sp + ".png"; this.ShieldPower = sp; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.shieldpower + "\r\n"); break; } case Properties.ANIMATION: // 10 this.Ani = Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.ani + "\r\n"); break; case Properties.HEADIMAGE: // 11 { Int32 len = Packet.ReadGUByte1(); this.HeadImage = (len < 100 ? "head" + len + ".png" : Packet.ReadChars(len - 100)); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.HeadImage + ""); break; } case Properties.CURCHAT: {// 12 this.Chat = Packet.ReadChars(Packet.ReadGUByte1()); //if (PlayerLevel != null) // PlayerLevel.CallNPCs("onPlayerChats", new object[] { this }); if (this.Chat != null && this.Chat != "" && this.Account != "" && this.Account != null) this.form.WriteText("(" + this.Account + ") " + this.Chat + ""); break; } case Properties.PLCOLORS: // 13 for (int i = 0; i < 5; i++) { this.ColorManager[i] = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.ColorManager[i] + "\r\n"); } break; case Properties.PLAYERID: // 14 { this.Id = (short)Packet.ReadGUByte2(); this.form.AddPlayer(this.Account, this.Account); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Id + ""); break; } case Properties.PLAYERX: // 15 - obsolete Packet.ReadGUByte1(); //this.X = ((double)Packet.ReadGUByte1() / 2); //moved = true; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); break; case Properties.PLAYERY: // 16 - obsolete Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); //this.Y = ((double)Packet.ReadGUByte1() / 2); //moved = true; break; case Properties.PLSPRITE: // 17 this.Dir = Packet.ReadGUByte1() % 4; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.dir + "\r\n"); break; case Properties.PLSTATUS: // 18 this.PlayerStatus = Packet.ReadGUByte1(); if ((this.PlayerStatus & (int)Status.DEAD) != 0) { //if (PlayerLevel != null) // PlayerLevel.CallNPCs("onPlayerDies", new object[] { this }); } //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.PlayerStatus + ""); break; case Properties.CARRYSPRITE: // 19 Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); break; case Properties.CURLEVEL: // 20 string levelName = Packet.ReadChars(Packet.ReadGUByte1()).Trim(); if (this.Level != null) this.Level.DeletePlayer(this); this.Level = Server.FindLevel(levelName); this.Level.AddPlayer(this); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Level.Name + ""); break; case Properties.HORSEIMG: // 21 Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadChars(Packet.ReadGUByte1()).ToString() + "\r\n"); break; case Properties.HORSEBUSHES: // 22 Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); break; case Properties.EFFECTCOLOR: // 23 { int len = Packet.ReadGUByte1(); if (len > 0) Packet.ReadGUByte4(); break; } case Properties.CARRYNPC: // 24 Packet.ReadGUByte3(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte3().ToString() + "\r\n"); break; case Properties.APCOUNTER: // 25 Packet.ReadGUByte2(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte2().ToString() + "\r\n"); break; case Properties.MAGICPOINTS: // 26 this.Magic = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Magic.ToString() + "\r\n"); break; case Properties.KILLSCOUNT: // 27 this.Kills = Packet.ReadGByte3(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.kills.ToString() + "\r\n"); break; case Properties.DEATHSCOUNT: // 28 this.Deaths = Packet.ReadGByte3(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.deaths.ToString() + "\r\n"); break; case Properties.ONLINESECS: // 29 this.OnlineTime = Packet.ReadGByte3(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.onlinetime.ToString() + "\r\n"); break; case Properties.IPADDRESS: // 30 this.IPAddress = new System.Net.IPAddress(Packet.ReadGUByte5()).ToString(); this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.IPAddress.ToString() + ""); break; case Properties.UDPPORT: // 31 int port = Packet.ReadGByte3(); this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + port.ToString() + ""); break; case Properties.ALIGNMENT: // 32 Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); break; case Properties.ADDITFLAGS: // 33 Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); break; case Properties.ACCOUNTNAME: // 34 this.Account = Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.Account + ""); break; case Properties.BODYIMAGE: // 35 this.BodyImage = Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.bodyimg + "\r\n"); break; case Properties.PLRATING: // 36 Packet.ReadGUByte3(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte3().ToString() + "\r\n"); break; case Properties.GATTRIB1: // 37 case Properties.GATTRIB2: // 38 case Properties.GATTRIB3: // 39 case Properties.GATTRIB4: // 40 case Properties.GATTRIB5: // 41 Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadChars(Packet.ReadGUByte1()).ToString() + "\r\n"); break; case Properties.PLATTACHNPC: // 42 Packet.ReadGUByte4(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte4().ToString() + "\r\n"); break; case Properties.GMAPLEVELX: // 43 GmapX = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + GmapX.ToString() + "\r\n"); break; case Properties.GMAPLEVELY: // 44 GmapY = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + GmapY.ToString() + "\r\n"); break; case Properties.PLAYERZ: // 45 Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte1().ToString() + "\r\n"); break; case Properties.GATTRIB6: // 46 case Properties.GATTRIB7: // 47 case Properties.GATTRIB8: // 48 case Properties.GATTRIB9: // 49 Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadChars(Packet.ReadGUByte1()).ToString() + "\r\n"); break; case Properties.JOINLEAVELV: // 50 byte joinLeaveLv = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + joinLeaveLv.ToString() + ""); break; case Properties.CONNECTED: // 51 { //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "] Disconnected\r\n"); this.form.RMPlayer(this.Account); Server.PlayerManager.DeletePlayer(Id); // disconnect player. break; } case Properties.LANGUAGE: // 52 Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadChars(Packet.ReadGUByte1()).ToString() + "\r\n"); break; case Properties.STATUSMSG: // 53 byte statusMsg = Packet.ReadGUByte1(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + statusMsg.ToString() + ""); break; case Properties.GATTRIB10: // 54 case Properties.GATTRIB11: // 55 case Properties.GATTRIB12: // 56 case Properties.GATTRIB13: // 57 case Properties.GATTRIB14: // 58 case Properties.GATTRIB15: // 59 case Properties.GATTRIB16: // 60 case Properties.GATTRIB17: // 61 case Properties.GATTRIB18: // 62 case Properties.GATTRIB19: // 63 case Properties.GATTRIB20: // 64 case Properties.GATTRIB21: // 65 case Properties.GATTRIB22: // 66 case Properties.GATTRIB23: // 67 case Properties.GATTRIB24: // 68 case Properties.GATTRIB25: // 69 case Properties.GATTRIB26: // 70 case Properties.GATTRIB27: // 71 case Properties.GATTRIB28: // 72 case Properties.GATTRIB29: // 73 case Properties.GATTRIB30: // 74 Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadChars(Packet.ReadGUByte1()).ToString() + "\r\n"); break; case Properties.OSTYPE: // 75 Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadChars(Packet.ReadGUByte1()).ToString() + ""); break; case Properties.TEXTCODEPG: // 76 Packet.ReadGUByte3(); this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte3().ToString() + ""); break; case Properties.UNKNOWN77: // 77 this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.Text.ToString() + ""); break; case Properties.PIXELX: // 78 { int tmp = this.PixelX = Packet.ReadGUByte2(); // If the first bit is 1, our position is negative. this.PixelX >>= 1; if ((tmp & 0x0001) != 0) this.PixelX = -this.PixelX; moved = true; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.PixelX.ToString() + "\r\n"); break; } case Properties.PIXELY: // 79 { int tmp = this.PixelY = Packet.ReadGUByte2(); // If the first bit is 1, our position is negative. this.PixelY >>= 1; if ((tmp & 0x0001) != 0) this.PixelY = -this.PixelY; moved = true; //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + this.PixelY.ToString() + "\r\n"); break; } case Properties.PIXELZ: // 80 Packet.ReadGUByte2(); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]" + Packet.ReadGUByte2().ToString() + "\r\n"); break; case Properties.UNKNOWN81: // 81 this.isLocalPlayer = false; this.form.WriteText("(" + this.Account + "(" + this.Id.ToString() + ")) I am on other server."); break; case Properties.COMMUNITY: // 82 string communityname = Packet.ReadChars(Packet.ReadGUByte1()); //this.form.WriteText("[" + this.Account + "(" + this.Id.ToString() + ")" + "][" + Enum.GetName(typeof(Properties), PropId).ToString() + "]: " + communityname + ""); break; default: { //this.form.WriteText("[" + PropId + "] " + Packet.Text + "\r\n"); this.form.WriteText("(" + this.Account + "(" + this.Id.ToString() + ")" + ") [" + PropId.ToString() + "]" + Packet.Text.ToString() + ""); break; } } } //if (moved && PlayerLevel != null) //{ //bool onGmap = PlayerLevel.Name.EndsWith(".gmap"); //GraalLevelNPC npc = PlayerLevel.isOnNPC(PixelX + touchtestd[dir*2], PixelY + touchtestd[dir*2+1]); //if (npc != null) // npc.Call("onPlayerTouchsMe", new object[] { this }); //} }
public void Save(CString pFileName) { CString stream = new CString(); stream += NW_LEVEL_VERSION + "\n"; // white space separator string s = " "; #region TILE code // write tiles for (int layer = 0; layer < this.layers.Count; layer++) { GraalLevelTileList tiles = this.layers[layer]; for (int y = 0; y < tiles.get_height(); y++) { string data = ""; // chunk start, chunk data pairs List<Dictionary<int, string>> chunks = new List<Dictionary<int, string>>(); /* Separate each row into chunks of actually non-transparent tiles. * Every time we encounter a transparent tile, flush the current data * into the chunk list and clear it. If we never encounter a transparent * tile, flush the entire data after the loop */ int current_start = 0; for (int x = 0; x < tiles.get_width(); x++) { //Console.WriteLine("Save x-y: " + x + "-" + y); GraalLevelTile tile = tiles.FindTile(x, y); if (tile.GetIndex() == tile.transparent_index) { if (data != null) { Dictionary<int, string> chunk = new Dictionary<int, string>(); current_start = x; data = null; chunk.Add(current_start, data); chunks.Add(chunk); } // Skip transparent tile current_start++; continue; } data += this.Base64Encode(tile.GetIndex()); } if (data != "") { Dictionary<int, string> chunk = new Dictionary<int, string>(); chunk.Add(current_start, data); ; chunks.Add(chunk); } /* Draw one BOARD entry for each chunk so transparent tile-data is culled */ foreach (Dictionary<int, string> chunk in chunks) { stream += "BOARD" + s + 0 + s + y + s + tiles.get_width() + s + layer + s; // x, y, width, layer foreach (string td in chunk.Values) stream += td; stream += "\n"; } } } #endregion #region LINK code foreach (KeyValuePair<int,GraalLevelLink> link in this.LinkList) { stream += "LINK" + s + link.Value.Destination + s + link.Value.X + s + link.Value.Y + s + link.Value.Width + s + link.Value.Height + s + link.Value.NewX + s + link.Value.NewY + "\n"; } #endregion #region SIGN code foreach (KeyValuePair<int,GraalLevelSign> sign in this.SignList) { stream += "SIGN" + s + sign.Value.X + s + sign.Value.Y + "\n"; stream += sign.Value.Text + "\n"; stream += "SIGNEND" + "\n"; } #endregion #region NPC code // Output the npc's from the NpcList foreach (KeyValuePair<int, GraalLevelNPC> npc in this.NpcList) { string image = npc.Value.Image; // If the npc does not have an image, use "-" if (image.Trim() == "") image = "-"; stream += "NPC" + s + image + s + (int)npc.Value.GMapX + s + (int)npc.Value.GMapY + "\n"; stream += npc.Value.Script + "\n"; stream += "NPCEND" + "\n"; } #endregion System.IO.StreamWriter nwFile = new System.IO.StreamWriter(pFileName.Text); nwFile.Write(stream.Text); nwFile.Flush(); nwFile.Close(); }
/// <summary> /// Append Packet to Buffer /// </summary> public void SendPacket(CString Packet, Boolean SendNow) { // Data Exist? if (Packet.Length < 1) return; // Append '\n' if (Packet[Packet.Length - 1] != '\n') Packet.WriteByte((byte)'\n'); // Append Data mDataOut.Write(Packet); // Check Buffer & Send if (SendNow || mDataOut.Length > 4096) SendCompress(); }
/// <summary> /// Abstract Function -> Handle Data /// </summary> protected virtual void HandleData(CString Packet) { }
/// <summary> /// Append Packet to Buffer & Send /// </summary> public void SendPacket(CString Packet) { SendPacket(Packet, true); }
/// <summary> /// Encrypt Packet /// </summary> public Encrypt.Type EncryptPacket(CString Packet) { // Encryption Type Encrypt.Type EncryptType = Encrypt.Type.UNCOMPRESSED; if (Packet.Length > 0x2000) { // 8192 EncryptType = Encrypt.Type.BZ2; Packet.BCompress(); } else if (Packet.Length > 0x28) { // 40 EncryptType = Encrypt.Type.ZLIB; Packet.WriteShort(0); Packet.ZCompress(); } // Apply Encryption mCodec.Limit(EncryptType); mCodec.Apply(Encrypt.CryptType.ENCRYPT, Packet); return EncryptType; }
/// <summary> /// Decrypt Packet /// </summary> public void DecryptPacket(CString Packet) { // Encryption Type Encrypt.Type EncryptType = Encrypt.Type.UNCOMPRESSED; // Generation Type switch (mCodec.Gen) { // Unencrypted Packets case Encrypt.Generation.GEN1: case Encrypt.Generation.GEN2: return; // Zlib case Encrypt.Generation.GEN3: mCodec.Apply(Encrypt.CryptType.DECRYPT, Packet, Encrypt.Type.UNCOMPRESSED); return; // BZip2 case Encrypt.Generation.GEN4: EncryptType = Encrypt.Type.BZ2; break; // BZip2 / Zlib case Encrypt.Generation.GEN5: EncryptType = (Encrypt.Type)Packet.ReadByte(); Packet.Remove(0, 1); break; } // Decrypt Packet mCodec.Apply(Encrypt.CryptType.DECRYPT, Packet, EncryptType); // Uncompress Packet if (EncryptType == Encrypt.Type.ZLIB) Packet.ZDecompress(); else if (EncryptType == Encrypt.Type.BZ2) Packet.BDecompress(); }
private bool LoadZelda(CString levelData, string fileVersion) { // Get the appropriate filesystem. //CFileSystem* fileSystem = server->getFileSystem(); //if (server->getSettings()->getBool("nofoldersconfig", false) == false) // fileSystem = server->getFileSystem(FS_LEVEL); // Path-To-File //actualLevelName = levelName = pLevelName; //fileName = fileSystem->find(pLevelName); //modTime = fileSystem->getModTime(pLevelName); // Check if it is actually a .graal level. The 1.39-1.41r1 client actually // saved .zelda as .graal. if (fileVersion.Substring(0, 2) == "GR") return this.LoadGraal(levelData, fileVersion); int v = -1; if (fileVersion == "Z3-V1.03") v = 3; else if (fileVersion == "Z3-V1.04") v = 4; if (v == -1) return false; #region Load tiles. bool layerExists = false; foreach (KeyValuePair<int, GraalLevelTileList> l in this.layers) if (l.Key == 0) layerExists = true; if (!layerExists) this.layers[0] = new GraalLevelTileList(); { int bits = (v > 4 ? 13 : 12); int read = 0; uint buffer = 0; long code = 0; int[] tiles = new int[2] { -1, -1 }; int boardIndex = 0; int count = 1; bool doubleMode = false; // Read the tiles. while (boardIndex < 64 * 64 && levelData.BytesLeft != 0) { // Every control code/tile is either 12 or 13 bits. WTF. // Read in the bits. while (read < bits) { buffer += ((uint)levelData.ReadGByte1()) << read; read += 8; } // Pull out a single 12/13 bit code from the buffer. code = buffer & (bits == 12 ? 0xFFF : 0x1FFF); buffer >>= bits; read -= bits; Console.WriteLine("Code&bits: " + (code & (bits == 12 ? 0x800 : 0x1000))); // See if we have an RLE control code. // Control codes determine how the RLE scheme works. if ((code & (bits == 12 ? 0x800 : 0x1000)) != 0) { // If the 0x100 bit is set, we are in a double repeat mode. // {double 4}56 = 56565656 if ((code & 0x100) != 0) doubleMode = true; // How many tiles do we count? count = (int)(code & 0xFF); continue; } // If our count is 1, just read in a tile. This is the default mode. if (count == 1) { GraalLevelTile tile = this.layers[0].AddTile(boardIndex++, (int)code); continue; } // If we reach here, we have an RLE scheme. // See if we are in double repeat mode or not. if (doubleMode) { // Read in our first tile. if (tiles[0] == -1) { tiles[0] = (int)code; continue; } // Read in our second tile. tiles[1] = (int)code; // Add the tiles now. for (int i = 0; i < count && boardIndex < 64 * 64 - 1; ++i) { GraalLevelTile tile = this.layers[0].AddTile(boardIndex++, tiles[0]); GraalLevelTile tile2 = this.layers[0].AddTile(boardIndex++, tiles[1]); } // Clean up. tiles[0] = tiles[1] = -1; doubleMode = false; count = 1; } // Regular RLE scheme. else { GraalLevelTile tile = null; for (int i = 0; i < count && boardIndex < 64 * 64; ++i) tile = this.layers[0].AddTile(boardIndex++, (int)code); count = 1; } } } #endregion #region Load the links. { while (levelData.BytesLeft != 0) { CString line = levelData.ReadString('\n'); if (line.Length == 0 || line.Text == "#") break; // Assemble the level string. CStringList vline = new CStringList(); vline.Load(line.Text, ' '); CString level = vline.Get(0); if (vline.Count > 7) { for (int i = 0; i < vline.Count - 7; ++i) level += " " + vline.Get(1 + i); } int offset = vline.Count - 7; //GraalLevelLink link = new GraalLevelLink(vline.Get(0).Text, vline.Get(1).ToInt(), vline.Get(2).ToInt(), vline.Get(3).ToInt(), vline.Get(4).ToInt(),vline.Get(5).Text, vline.Get(6).Text); //this.LinkList.Add(this.LinkList.Count + 1, link); } } #endregion #region Load the baddies. { while (levelData.BytesLeft != 0) { int x = levelData.ReadGUByte1(); int y = levelData.ReadGUByte1(); int type = levelData.ReadGUByte1(); // Ends with an invalid baddy. if (x == -1 && y == -1 && type == -1) { levelData.ReadString('\n'); // Empty verses. break; } /* // Add the baddy. TLevelBaddy* baddy = addBaddy((float)x, (float)y, type); if (baddy == 0) continue; // Only v1.04+ baddies have verses. if (v > 3) { // Load the verses. std::vector<CString> bverse = fileData.readString("\n").tokenize("\\"); CString props; for (char j = 0; j < (char)bverse.size(); ++j) props >> (char)(BDPROP_VERSESIGHT + j) >> (char)bverse[j].length() << bverse[j]; if (props.length() != 0) baddy->setProps(props); } */ } } #endregion #region Load signs. { while (levelData.BytesLeft != 0) { CString line = levelData.ReadString('\n'); if (line.Length == 0) break; byte x = line.ReadGUByte1(); byte y = line.ReadGUByte1(); CString text = line.ReadString(); this.SignList.Add(this.SignList.Count + 1, new GraalLevelSign(x, y, text.Text)); } } #endregion return true; }
public void ReceivedToall(GraalPlayer Player, CString Message) { this.form = Abstraction.GetInstance(); ToallsWindow PM = ToallsWindow.GetInstance(); if (PM != null) { PM.SetMessage(Player, Message); } }
public virtual bool AddNPC(bool isNpcCodeLine, CString lvlDat, CStringList words, string type) { if (isNpcCodeLine) { if (type == "NPCEND") { isNpcCodeLine = false; } else { GraalLevelNPC npc = this.NpcList[this.NpcList.Count]; npc.Script += lvlDat.Text; npc.Script += "\n"; this.NpcList[this.NpcList.Count] = npc; } } else { GraalLevelNPC npc = new GraalLevelNPC(this, this.NpcList.Count + 1); npc.Image = words.Get(1).Text; if (npc.Image == "-") npc.Image = ""; float rx, ry; float.TryParse(words.Get(2).Text, out rx); float.TryParse(words.Get(3).Text, out ry); npc.GMapX = (byte)rx; npc.GMapY = (byte)ry; npc.PixelX = Convert.ToInt32(npc.GMapX * 16.0); npc.PixelY = Convert.ToInt32(npc.GMapY * 16.0); isNpcCodeLine = true; this.NpcList.Add(this.NpcList.Count + 1, npc); } return isNpcCodeLine; }
/// <summary> /// Set Properties /// </summary> public void SetMessage(CString Packet) { Gtk.Application.Invoke(delegate { this.LastMessage = Packet; if (this.PMPlayer != null) this.WriteText("(" + this.PMPlayer.Nickname + "): " + Packet.Untokenize().Text.Trim()); this.Show(); } ); }
public override void ReceivedFileBrowserMessage(CString message) { Gtk.Application.Invoke(delegate { RCFileBrowser.GetInstance().SetMessage(message); RCFileBrowser.GetInstance().ShowAll(); }); }
//public override void Disconnect() //{ // base.Disconnect(); //} /// <summary> /// Handle Login Packet /// </summary> protected void HandleLogin(CString LoginPacket) { // Check Type & Version Int32 type = LoginPacket.ReadGUByte1(); String version = LoginPacket.ReadChars(8); if (type != 3 || version != "NCL21075") { SendPacket(new CString() + (byte)16 + "Your nc version is not allowed on this server.", true); this.Disconnect(); return; } // Send Login data for verification Account = LoginPacket.ReadChars(LoginPacket.ReadGUByte1()); Password = LoginPacket.ReadChars(LoginPacket.ReadGUByte1()); //server->sendToGserver(CString() >> (char)GO_REQUEST_RIGHTS << account); // Send NC Login SendPacket(new CString() + (byte)PacketOut.NC_CHAT + "Welcome to the NPC-Server for NPC-Server Test"); Server.SendNCChat("New NC: " + Account, this); // Send Current NC's foreach (NCConnection nc in Server.NCList) { if (nc != this) SendPacket(new CString() + (byte)PacketOut.NC_CHAT + "New NC: " + Account); } /* // Send Classes std::map<CString, TScriptClass *> *classList = mServer->getClassList(); for (std::map<CString, TScriptClass *>::const_iterator i = classList->begin(); i != classList->end(); ++i) sendPacket(CString() >> (char)PLO_NC_CLASSADD << i->first); // Send Npcs std::map<int, TScriptNPC *> *npcList = mServer->getNpcList(); for (std::map<int, TScriptNPC *>::const_iterator i = npcList->begin(); i != npcList->end(); ++i) sendPacket(CString() << i->second->GetNpcPacket()); */ // Set Login LoggedIn = true; }
public override void ReceivedNpcServerAddress(CString ip, CString port) { this.WriteText("NpcServer - IP: "+ ip.Text + " - Port: " + port.Text); Server.InitNcConnection(ip,port); }
/// <summary> /// Send Login Information /// </summary> public void SendLogin(String Account, String Password, String Nickname) { // Send Login CString LoginPacket = new CString () + (byte)2 + "GRNS0000" + (byte)Account.Length + Account + (byte)Password.Length + Password + (short)AppSettings.GetInstance ().NCPort + "\n" + (byte)PacketOut.PLAYERPROPS + (byte)0 + (byte)Nickname.Length + Nickname + "\n"; LoginPacket.ZCompress ().PreLength (); this.Send (LoginPacket.Buffer); }
/// <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); 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().Text; 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; } // 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); 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(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; } default: System.Console.WriteLine("CLIENTNC -> Packet [" + PacketId + "]: " + CurPacket.Text); break; } } }
/// <summary> /// Send Packet to everyone but sender /// </summary> public void SendPacket(CString Packet, NCConnection Sender) { /* List<NCConnection> _tmpNCList = new List<NCConnection>(); foreach (NCConnection nc in NCList) { _tmpNCList.Add(nc); } */ lock (NCList) { foreach (NCConnection nc in NCList) { if (nc != Sender) { if (nc.Connected) { Console.WriteLine("[NCOUT]: " + Packet.ToString()); nc.SendPacket(Packet, true); } //else Console.WriteLine("Failed to send data to NC!"); } } } //_tmpNCList.Clear (); //_tmpNCList = null; }