private static void CheckMotdPackets() { if (MOTDNonAdmin.bytes == null) { MOTDNonAdmin.Add(Packet.Types.MOTD); MOTDNonAdmin.Add(ServerSettings.Version); MOTDNonAdmin.Add(ServerSettings.GetSetting("ServerName"), 64); MOTDNonAdmin.Add(ServerSettings.GetSetting("motd"), 64); MOTDNonAdmin.Add((byte)0); MOTDAdmin = MOTDNonAdmin; MOTDAdmin.bytes[130] = 100; } }
public void Use(Player p, string[] args) { ExtraPlayerData z = ZombiePlugin.ZombiePlugin.FindPlayer(p); z.Aka = !z.Aka; foreach (Player e in Server.Players.ToArray()) { Packet pa = new Packet(new byte[2] { (byte)Packet.Types.SendDie, e.ID }); if (p != e) { p.SendPacket(pa); } } p.SpawnOtherPlayersForThisPlayer(); p.SendMessage("Aka mode is now " + z.Aka.ToString().Replace("True", "on!").Replace("False", "off!")); }
public void Use(Player p, string[] args) { if (args.Count() != 0) { Help(p); return; } Vector3S meep = new Vector3S((short)(16 + p.Level.CWMap.SpawnPos.x * 32), (short)(16 + p.Level.CWMap.SpawnPos.z * 32), (short)(p.Level.CWMap.SpawnPos.y * 32)); Packet pa = new Packet(); pa.Add(Packet.Types.SendTeleport); pa.Add((byte)0xff); pa.Add(meep.x); pa.Add(meep.y); pa.Add(meep.z); pa.Add(new byte[2] { (byte)p.Level.CWMap.SpawnRotation.x, (byte)p.Level.CWMap.SpawnRotation.z }); p.SendPacket(pa); }
public void Use(Player p, string[] args) { if (args.Count() != 0) { Help(p); return; } Vector3S meep = new Vector3S((short)(p.Level.SpawnPos.x * 32), (short)(p.Level.SpawnPos.z * 32 + 51), (short)(p.Level.SpawnPos.y * 32)); Packet pa = new Packet(); pa.Add(Packet.Types.SendTeleport); pa.Add(unchecked((byte)-1)); //If the ID is not greater than one it doesn't work :c pa.Add(meep.x); pa.Add(meep.y); pa.Add(meep.z); pa.Add(p.Rot); p.SendPacket(pa); }
/// <summary> /// Sends the specified player to the specified coordinates. /// </summary> /// <param name="_pos"></param>Vector3 coordinate to send to. /// <param name="_rot"></param>Rot to send to. public void SendToPos(Vector3S _pos, byte[] _rot) { oldPos = Pos; oldRot = Rot; _pos.x = (_pos.x < 0) ? (short)32 : (_pos.x > Level.Size.x * 32) ? (short)(Level.Size.x * 32 - 32) : (_pos.x > 32767) ? (short)32730 : _pos.x; _pos.z = (_pos.z < 0) ? (short)32 : (_pos.z > Level.Size.z * 32) ? (short)(Level.Size.z * 32 - 32) : (_pos.z > 32767) ? (short)32730 : _pos.z; _pos.y = (_pos.y < 0) ? (short)32 : (_pos.y > Level.Size.y * 32) ? (short)(Level.Size.y * 32 - 32) : (_pos.y > 32767) ? (short)32730 : _pos.y; Packet pa = new Packet(); pa.Add(Packet.Types.SendTeleport); pa.Add(unchecked((byte)-1)); //If the ID is not greater than one it doesn't work :c pa.Add(_pos.x); pa.Add(_pos.y); pa.Add(_pos.z); pa.Add(Rot); SendPacket(pa); }
public Packet(Packet p) { bytes = p.bytes; }
void OnOutgoingData(Player p, PacketEventArgs e) { if (e.Type == Packet.Types.MOTD) { string ip; if (Server.DebugMode) { ip = "127.0.0.1"; } else { ip = InetUtils.GrabWebpage("http://www.mcforge.net/serverdata/ip.php"); } Packet pa = new Packet(); pa.Add(Packet.Types.MOTD); pa.Add((byte)7); pa.Add(ServerSettings.GetSetting("ServerName"), 64); pa.Add(ServerSettings.GetSetting("MOTD") + " &0cfg=" + ip + ":" + ServerSettings.GetSetting("Port") + "/" + p.Level.Name, 64); pa.Add((byte)0); e.Data = pa.bytes; } //Because this is way more fun and requires no edits to the core ~Gamemakergm else if (e.Type == Packet.Types.Message) { if (PluginSettings.GetSettingBoolean("joinleave-alert")) { string incoming = Encoding.ASCII.GetString(e.Data).Trim(); //Logger.Log(incoming); if (incoming.Contains("joined the game!")) { e.Cancel(); WOM.GlobalSendJoin(incoming.Substring(1, incoming.Length - incoming.IndexOf("joined the game!"))); } else if (incoming.Contains("has disconnected")) { e.Cancel(); WOM.GlobalSendLeave(incoming.Substring(1, incoming.Length - incoming.IndexOf("has disconnected"))); } } } else { return; } }
public void SendHoldThis(byte type, byte locked) { // if locked is on 1, then the player can't change their selected block. Packet pa = new Packet(); pa.Add(Packet.Types.HoldThis); pa.Add(type); pa.Add(locked); SendPacket(pa); }
public void SendExtEntry(string name, int version) { Packet pa = new Packet(); pa.Add(Packet.Types.ExtEntry); pa.Add(name, 64); pa.Add(version); SendPacket(pa); }
private void HandleLogin(byte[] message) { try { if (IsLoggedIn) return; byte version = message[0]; Username = enc.GetString(message, 1, 64).Trim(); _displayName = Username; string BanReason = null; bool banned = false; foreach (string line in File.ReadAllLines("bans/BanInfo.txt")) { if (Username == line.Split('`')[0]) { BanReason = line.Split('`')[1]; } } foreach (string line in Server.IPBans) { if (line == Ip) banned = true; } foreach (string line in Server.UsernameBans) { if (line == Username) banned = true; } if (banned) { if (BanReason == "No reason given.") { SKick("You are banned because " + BanReason); } else { SKick("You are banned!"); } } string verify = enc.GetString(message, 65, 32).Trim(); byte type = message[129]; if (!VerifyAccount(Username, verify)) return; if (Server.Verifying) IsVerified = false; else IsVerified = true; if (version != ServerSettings.Version) { SKick("Wrong Version!"); return; } try { Server.TempBan tb = Server.TempBansList.Find(ban => ban.name.ToLower() == Username.ToLower()); if (DateTime.Now > tb.allowed) { Server.TempBansList.Remove(tb); } else { SKick("You're still tempbanned!"); return; } } catch { } ConnectionEventArgs eargs = new ConnectionEventArgs(true); bool cancel = OnPlayerConnect.Call(this, eargs, OnAllPlayersConnect).Canceled; if (cancel) { Kick("Disconnected by canceled ConnectionEventArgs!"); } Gotos_Are_The_Devil: if (Server.PlayerCount >= ServerSettings.GetSettingInt("MaxPlayers") && !Server.VIPs.Contains(Username) && !Server.Devs.Contains(Username)) { int LoopAmount = 0; while (Server.PlayerCount >= ServerSettings.GetSettingInt("MaxPlayers")) { LoopAmount++; Thread.Sleep(1000); Packet pa = new Packet(); pa.Add(Packet.Types.MOTD); pa.Add(ServerSettings.Version); pa.Add("Waiting in queue, waiting for " + LoopAmount + " seconds", 64); pa.Add(Server.PlayerCount + " players are online right now out of " + ServerSettings.GetSettingInt("MaxPlayers") + "!", 64); pa.Add((byte)0); SendPacket(pa); } } //TODO Database Stuff Logger.Log("[System]: " + Ip + " logging in as " + Username + ".", System.Drawing.Color.Green, System.Drawing.Color.Black); try { Server.IRC.SendMessage(Username + " joined the game!"); } catch { } UniversalChat(Username + " joined the game!"); //WOM.SendJoin(Username); CheckDuplicatePlayers(Username); foreach (PlayerGroup g in PlayerGroup.Groups) if (g.Players.Contains(Username.ToLower())) Group = g; ExtraData.CreateIfNotExist("HasMarked", false); ExtraData.CreateIfNotExist("Mark1", new Vector3S()); ExtraData.CreateIfNotExist("Mark2", new Vector3S()); SendMotd(); IsLoading = true; IsLoggedIn = true; if (Level == null) Level = Server.Mainlevel; else Level = Level; ID = FreeId(); if (Server.PlayerCount >= ServerSettings.GetSettingInt("MaxPlayers")) goto Gotos_Are_The_Devil; //Gotos are literally the devil, but it works here so two players dont login at once UpgradeConnectionToPlayer(); short x = (short)((0.5 + Level.SpawnPos.x) * 32); short y = (short)((1 + Level.SpawnPos.y) * 32); short z = (short)((0.5 + Level.SpawnPos.z) * 32); Pos = new Vector3S(x, z, y); Rot = Level.SpawnRot; oldPos = Pos; oldRot = Rot; SendSpawn(this); SpawnThisPlayerToOtherPlayers(); UpdatePosition(true); SpawnOtherPlayersForThisPlayer(); SpawnBotsForThisPlayer(); IsLoading = false; //Load from Database Load(); foreach (string w in ServerSettings.GetSetting("welcomemessage").Split(new string[] { "<br>" }, StringSplitOptions.RemoveEmptyEntries)) SendMessage(w); } catch (Exception e) { Logger.LogError(e); } }
private void SendMessage(byte PlayerID, string message) { for (int i = 0; i < 10; i++) { message = message.Replace("%" + i, "&" + i); message = message.Replace("&" + i + " &", "&"); } for (char ch = 'a'; ch <= 'f'; ch++) { message = message.Replace("%" + ch, "&" + ch); message = message.Replace("&" + ch + " &", "&"); } if (!String.IsNullOrWhiteSpace(message) && message.IndexOf("^detail.user") == -1) message = Server.DefaultColor + message; try { foreach (string line in LineWrapping(message)) { Packet pa = new Packet(); pa.Add(Packet.Types.Message); pa.Add(PlayerID); pa.Add(line, 64); SendPacket(pa); } } catch (Exception e) { Logger.LogError(e); } }
public void SendTextHotKey(string label, string command, int keycode, byte mods) { Packet pa = new Packet(); pa.Add(Packet.Types.SetTextHotKey); pa.Add(label, 64); pa.Add(command, 64); pa.Add(keycode); pa.Add(mods); SendPacket(pa); }
public void SendExtRemovePlayerName(short id) { Packet pa = new Packet(); pa.Add(Packet.Types.ExtRemovePlayerName); pa.Add(id); SendPacket(pa); }
public void SendSetMapWeather(byte weather) { // 0 - sunny; 1 - raining; 2 - snowing Packet pa = new Packet(); pa.Add(Packet.Types.EnvWeatherType); pa.Add(weather); SendPacket(pa); }
public void SendSpawn(Player p) { byte ID = 0xFF; if (p != this) ID = p.ID; Packet pa = new Packet(); pa.Add(Packet.Types.SendSpawn); pa.Add((byte)ID); pa.Add(p._displayName, 64); pa.Add(p.Pos.x); pa.Add((ushort)(p.Pos.y + ((ID == 0xFF) ? -21 : 3))); pa.Add(p.Pos.z); pa.Add(new byte[2] { (byte)p.Rot.x, (byte)p.Rot.z }); SendPacket(pa); p.UpdatePosition(true); }
public void SendSetMapAppearance(string url, byte sideblock, byte edgeblock, short sidelevel) { Packet pa = new Packet(); pa.Add(Packet.Types.EnvMapAppearance); byte[] buffer = new byte[68]; pa.Add(url, 64); pa.Add(sideblock); pa.Add(edgeblock); pa.Add(sidelevel); SendPacket(pa); }
public void SendSetBlockPermission(byte type, byte canplace, byte candelete) { Packet pa = new Packet(); pa.Add(Packet.Types.SetBlockPermission); pa.Add(canplace); pa.Add(candelete); SendPacket(pa); }
public void SendMakeSelection(byte id, string label, short smallx, short smally, short smallz, short bigx, short bigy, short bigz, short r, short g, short b, short opacity) { Packet pa = new Packet(); pa.Add(Packet.Types.MakeSelection); pa.Add(id); pa.Add(label, 64); pa.Add(smallx); pa.Add(smally); pa.Add(smallz); pa.Add(bigx); pa.Add(bigy); pa.Add(bigz); pa.Add(r); pa.Add(g); pa.Add(b); pa.Add(opacity); SendPacket(pa); }
internal void UpdatePosition(bool ForceTp) { Vector3S tempOldPos = new Vector3S(oldPos); Vector3S tempPos = new Vector3S(Pos); byte[] tempRot = Rot; byte[] tempOldRot = oldRot; if (tempOldRot == null) tempOldRot = new byte[2]; if (IsHeadFlipped) tempRot[1] = 125; oldPos = tempPos; oldRot = tempRot; short diffX = (short)(tempPos.x - tempOldPos.x); short diffZ = (short)(tempPos.z - tempOldPos.z); short diffY = (short)(tempPos.y - tempOldPos.y); int diffR0 = tempRot[0] - tempOldRot[0]; int diffR1 = tempRot[1] - tempOldRot[1]; //TODO rewrite local pos change code if (diffX == 0 && diffY == 0 && diffZ == 0 && diffR0 == 0 && diffR1 == 0) { return; //No changes } bool teleport = ForceTp || (Math.Abs(diffX) >= 127 || Math.Abs(diffY) >= 127 || Math.Abs(diffZ) >= 127) || true; //Leave true untill issue 38 is fixed! Packet pa = new Packet(); if (teleport) { pa.Add(Packet.Types.SendTeleport); pa.Add(ID); pa.Add(tempPos.x); pa.Add(tempPos.y); pa.Add(tempPos.z); pa.Add(tempRot); } else { bool rotupdate = diffR0 != 0 || diffR1 != 0; bool posupdate = diffX != 0 || diffY != 0 || diffZ != 0; if (rotupdate && posupdate) { pa.Add(Packet.Types.SendPosANDRotChange); pa.Add(ID); pa.Add((sbyte)diffX); pa.Add((sbyte)diffY); pa.Add((sbyte)diffZ); pa.Add(tempRot); } else if (rotupdate) { pa.Add(Packet.Types.SendRotChange); pa.Add(ID); pa.Add(tempRot); } else if (posupdate) { pa.Add(Packet.Types.SendPosChange); pa.Add(ID); pa.Add((sbyte)(diffX)); pa.Add((sbyte)(diffY)); pa.Add((sbyte)(diffZ)); } else return; } Server.ForeachPlayer(delegate(Player p) { if (p != this && p.Level == Level && p.IsLoggedIn && !p.IsLoading) { p.SendPacket(pa); } }); }
public void SendSpawn(Player p) { byte ID = 0xFF; if (p != this) ID = p.ID; Packet pa = new Packet(); pa.Add(Packet.Types.SendSpawn); pa.Add((byte)ID); pa.Add(p._displayName, 64); pa.Add(p.Pos.x); pa.Add(p.Pos.y); pa.Add(p.Pos.z); pa.Add(p.Rot); SendPacket(pa); p.UpdatePosition(true); }
/// <summary> /// Kill this player for everyone. /// </summary> public void GlobalDie() { Packet pa = new Packet(new byte[2] { (byte)Packet.Types.SendDie, ID }); Server.ForeachPlayer(p => { if (p != this) { p.SendPacket(pa); } }); }
private void SendKick(string message) { Packet pa = new Packet(); pa.Add(Packet.Types.SendKick); pa.Add(message, 64); SendPacket(pa); }
public override void SendPacket(Packet pa) { PacketEventArgs args = new PacketEventArgs(pa.bytes, false, (Packet.Types)pa.bytes[0]); bool Canceled = OnPlayerSendPacket.Call(this, args, OnAllPlayersSendPacket).Canceled; if (pa.bytes != args.Data) pa.bytes = args.Data; if (!Canceled) { try { lastPacket = (Packet.Types)pa.bytes[0]; } catch (Exception e) { Logger.LogError(e); } for (int i = 0; i < 3; i++) { try { lastPacket = (Packet.Types)pa.bytes[0]; } catch (Exception e) { Logger.LogError(e); } for (int z = 0; z < 3; z++) { try { Socket.BeginSend(pa.bytes, 0, pa.bytes.Length, SocketFlags.None, delegate(IAsyncResult result) { }, null); return; } catch { continue; } } CloseConnection(); } } }
public void SendExtAddPlayerName(short id, string name, PlayerGroup grp, string displayname = "") { Packet pa = new Packet(); pa.Add(Packet.Types.ExtAddPlayerName); pa.Add(id); pa.Add(name, 64); if (displayname == "") { displayname = Color + name; } pa.Add(displayname, 64); pa.Add(grp.Name.ToUpper() + "s:", 64); pa.Add((byte)(grp.Permission)); SendPacket(pa); }
private void SendMap() { try { IsLoading = true; SendPacket(mapSendStartPacket); //Send the pre-fab map start packet Packet pa = new Packet(); //Create a packet to handle the data for the map pa.Add(Level.TotalBlocks); //Add the total amount of blocks to the packet byte[] blocks = new byte[Level.TotalBlocks]; //Temporary byte array so we dont have to keep modding the packet array byte block; //A block byte outside the loop, we save cycles by not making this for every loop iteration Level.ForEachBlock(pos => { //Here we loop through the whole map and check/convert the blocks as necesary //We then add them to our blocks array so we can send them to the player block = Level.Data[pos]; //TODO ADD CHECKING blocks[pos] = block; }); pa.Add(blocks); //add the blocks to the packet pa.GZip(); //GZip the packet int number = (int)Math.Ceiling(((double)(pa.bytes.Length)) / 1024); //The magic number for this packet for (int i = 1; pa.bytes.Length > 0; ++i) { short length = (short)Math.Min(pa.bytes.Length, 1024); byte[] send = new byte[1027]; Packet.HTNO(length).CopyTo(send, 0); Buffer.BlockCopy(pa.bytes, 0, send, 2, length); byte[] tempbuffer = new byte[pa.bytes.Length - length]; Buffer.BlockCopy(pa.bytes, length, tempbuffer, 0, pa.bytes.Length - length); pa.bytes = tempbuffer; send[1026] = (byte)(i * 100 / number); Packet Send = new Packet(send); Send.AddStart(new byte[1] { (byte)Packet.Types.MapData }); SendPacket(Send); } pa = new Packet(); pa.Add(Packet.Types.MapEnd); pa.Add((short)Level.Size.x); pa.Add((short)Level.Size.y); pa.Add((short)Level.Size.z); SendPacket(pa); IsLoading = false; } catch (Exception e) { Logger.LogError(e); } }
public void SendHackControl(byte allowflying, byte allownoclip, byte allowspeeding, byte allowrespawning, byte allowthirdperson, byte allowchangingweather, short maxjumpheight) { Packet pa = new Packet(); pa.Add(Packet.Types.HackControl); pa.Add(allowflying); pa.Add(allownoclip); pa.Add(allowspeeding); pa.Add(allowrespawning); pa.Add(allowthirdperson); pa.Add(allowchangingweather); pa.Add(maxjumpheight); SendPacket(pa); }
/// <summary> /// This send a blockchange to the player only. (Not other players) /// </summary> /// <param name="x">The position the block will be placed in (x)</param> /// <param name="z"> The position the block will be placed in (z)</param> /// <param name="y"> The position the block will be placed in (y)</param> /// <param name="type"> The type of block that will be placed.</param> public void SendBlockChange(ushort x, ushort z, ushort y, byte type) { if (x < 0 || y < 0 || z < 0 || x >= Level.Size.x || y >= Level.Size.y || z >= Level.Size.z) return; Packet pa = new Packet(); pa.Add(Packet.Types.SendBlockchange); pa.Add(x); pa.Add(y); pa.Add(z); //if (type > 49) type = Block.CustomBlocks[type].VisibleType; pa.Add(type); SendPacket(pa); }
void OnPlayerMove_Normal(Player sender, MCForge.API.Events.MoveEventArgs args) { int count = (int)sender.ExtraData["RunCounter"]; count++; sender.ExtraData["RunCounter"] = count; if (count % 15 != 0) return; sender.ExtraData["RunCounter"] = 0; Vector3S tmpPos = new Vector3S(args.FromPosition); tmpPos.Horizontal = tmpPos.Horizontal.GetMove(320, args.ToPosition.Horizontal); if (tmpPos.x < 32 || tmpPos.z < 32 || tmpPos.x > (sender.Level.CWMap.Size.x - 1) * 32 || tmpPos.z > (sender.Level.CWMap.Size.z - 1) * 32) return; Packet pa = new Packet(); pa.Add(Packet.Types.SendTeleport); pa.Add((sbyte)-1); pa.Add(tmpPos.x); pa.Add((short)(tmpPos.y)); pa.Add(tmpPos.z); pa.Add(new byte[2] { (byte)sender.Rot.x, (byte)sender.Rot.z }); sender.oldPos = tmpPos; sender.Pos = tmpPos; sender.oldRot = sender.Rot; sender.SendPacket(pa); args.Cancel(); count++; }
/// <summary> /// Exactly what the function name is, it might be useful to change this players pos first ;) /// </summary> public void SendThisPlayerTheirOwnPos() { Packet pa = new Packet(); pa.Add(Packet.Types.SendTeleport); pa.Add((byte)255); pa.Add(Pos.x); pa.Add(Pos.y); pa.Add(Pos.z); pa.Add(Rot); SendPacket(pa); }
public void SendExtAddEntity(byte id, string name, string displayname = "") { Packet pa = new Packet(); pa.Add(Packet.Types.ExtAddEntity); byte[] buffer = new byte[129]; buffer[0] = id; pa.Add(name, 64); if (displayname == "") { displayname = name; } pa.Add(displayname, 64); SendPacket(pa); }