public void OnAnimation(ref PacketReader _pReader, PacketType pt, ref ClientManager _client) { AnimationPacket p = new AnimationPacket(PacketType.Animation); p.EntityID = _pReader.ReadInt(); p.Animation = _pReader.ReadByte(); p.BuildPacket(); int index_me = Chunk.GetIndex((int)_client._player.position.X, (int)_client._player.position.Y, (int)_client._player.position.Z); ClientManager[] player = GridServer.player_list; for (int i = 0; i < player.Length; i++) { if (player[i] == null) { } else { int index_remote = Chunk.GetIndex((int)player[i]._player.position.X, (int)player[i]._player.position.Y, (int)player[i]._player.position.Z); if (index_remote - 5 < index_me && index_remote + 5 > index_me && _client.id != player[i].id) { player[i].SendPacket(p, player[i].id, ref player[i], false, false); } } } _client.SendPacket(p, _client.id, ref _client, false, false); }
public void OnLoginRequest(ref PacketReader _pReader, PacketType pt, ref ClientManager _client) { //[int('protoVersion'), //str16('username'), //long(/*seed*/), //int(/*mode*/), //byte(/*world*/), //byte(), //ubyte(/*height*/), //ubyte(/*maxPlayers*/)] int version = _pReader.ReadInt(); string username = _pReader.ReadString(); string empty_string = _pReader.ReadString(); _pReader.ReadInt(); _pReader.ReadInt(); _pReader.ReadByte(); _pReader.ReadByte(); _pReader.ReadByte(); /* Protocol Version int 20 1.2.5's protocol version is 29 Username string TkTech The name of the user attempting to login, max length of 16 Not used string (empty string) Not used int 0 Not used int 0 Not used byte 0 Not used unsigned byte 0 Not used unsigned byte 0 */ #region Login Handler Packet LoginHandlerPacket p = new LoginHandlerPacket(pt); p.EntityID = _client.id; p.NotUsed = ""; p.LevelType = (string)Config.Configuration["LevelType"]; p.ServerMode = (int)Config.Configuration["ServerMode"]; p.Dimension = 0; p.Difficulty = 1; p.WorldHeight = 0; p.MaxPlayers = (byte)(int)Config.Configuration["MaxPlayers"]; p.BuildPacket(); _client.SendPacket(p, _client.id, ref _client, false, false); try { int i = 0; for (; i < base.ModuleAddons.Count; i++) { base.ModuleAddons.ElementAt(i).Value(pt, ModuleAddons.ElementAt(i).Key, ref _pReader, (PacketHandler)p, ref _client); } } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message + " Source:" + e.Source + " Method:" + e.TargetSite + " Data:" + e.Data); } #endregion Login Handler Packet }
public void OnSpwanPosition(ref PacketReader _pReader, PacketType pt, ref ClientManager _client) { PlayerPositionPacket p = new PlayerPositionPacket(PacketType.SpwanPosition); p.X = _client._player.position.X; p.Y = _client._player.position.Z; p.Z = _client._player.position.Y; p.BuildPacket(); int i = 0; _client.SendPacket(p, _client.id, ref _client, false, false); for (; i < base.ModuleAddons.Count; i++) { base.ModuleAddons.ElementAt(i).Value(PacketType.SpwanPosition, ModuleAddons.ElementAt(i).Key, ref _pReader, (PacketHandler)p, ref _client); } p = null; }
//NO LONGER NEEDED. public PacketHandler OnSpwanPositionHandler(PacketType p_type, string CustomPacketType, ref PacketReader _pReader, PacketHandler _p, ref ClientManager cm) { SpawnPlayerPacket p = new SpawnPlayerPacket(PacketType.SpwanPosition); p.X = cm._player.position.X; p.Y = cm._player.position.Z; p.Z = cm._player.position.Y; p.BuildPacket(); cm.SendPacket(p, cm.id, ref cm, false, false); int i = 0; for (; i < base.ModuleAddons.Count; i++) { base.ModuleAddons.ElementAt(i).Value(PacketType.SpwanPosition, ModuleAddons.ElementAt(i).Key, ref _pReader, (PacketHandler)p, ref cm); } p = null; return _p; }
public void OnChatMessage(ref PacketReader _pReader, PacketType pt, ref ClientManager _client) { string message = _pReader.ReadString(); ChatMessagePacket ChatMessage = new ChatMessagePacket(PacketType.ChatMessage); ChatMessage.MessageRecieved = message; ChatMessage.MessageSent = ""; if (message[0] == '/' && (bool)Config.Configuration["EnableEmbeddedChatCommands"]) { string command = message.Substring(1, message.Length - 1).ToLower(); string[] commands = command.Split(' '); switch (commands[0]) { case "save": ChatMessage.MessageSent = _client._player.name + ": " + "Saving World...."; World.SaveWorld(); ChatMessage.MessageSent = _client._player.name + ": " + "World Saved!"; break; case "set": switch (commands[1]) { case "-b": switch (commands[2]) { case "1": break; case "2": break; case "3": break; case "4": break; } break; } break; default: ChatMessage.MessageSent = "There is no such command please try again!"; break; } string[] data = command.Split((" ").ToCharArray()); // command.Split((" ").ToCharArray()); switch (data[0]) { case "tp": bool UniqueUserNames = true; PlayerClass player1 = null, player2 = null; foreach (ClientManager _user1 in GridServer.player_list) { if ((_user1 != null) && (_user1._player.name.ToLower().StartsWith(data[1]))) { if (player1 == null) { player1 = _user1._player; } else { UniqueUserNames = false; break; } } if ((_user1 != null) && (_user1._player.name.ToLower().StartsWith(data[2]))) { if (player2 == null) { player2 = _user1._player; } else { UniqueUserNames = false; break; } } } if (player1 != null & player2 != null & UniqueUserNames == true) { player2.position = player1.position; PlayerPositionAndLookPacket tp_packet = new PlayerPositionAndLookPacket(PacketType.PlayerPositionLook); tp_packet.OnGround = player2.onGround; tp_packet.Pitch = player2.Pitch; tp_packet.Stance = player2.stance; tp_packet.X = player2.position.X; tp_packet.Y = player2.position.Y; tp_packet.Z = player2.position.Z; tp_packet.Yaw = player2.Yaw; tp_packet.BuildPacket(); _client.SendPacket((PacketHandler)tp_packet, _client.id, ref _client, false, false); ChatMessage.MessageSent = player1.name + " teleported to " + player2.name; } else { ChatMessage.MessageSent = _client._player.name + ": " + "Cannot find user/wrong syntax"; GridServer.SendToPlayer((PacketHandler)ChatMessage, _client.id); } break; case "kick": foreach (ClientManager _user1 in GridServer.player_list) { if ((_user1 != null) && (_user1._player.name.ToLower().StartsWith(data[1])) && _user1._player.Rank <= RankLevel.Moderator) { DisconnectKick dk_packet = new DisconnectKick(PacketType.Disconnect_Kick); dk_packet.Reason = "You have been kicked by " + _client._player.name + ", bitch!"; dk_packet.BuildPacket(); ClientManager test = _user1; _client.SendPacket((PacketHandler)dk_packet, _user1.id, ref test, false, false); } } break; default: //ChatMessage.MessageSent = "There is no such command please try again!"; break; } try { int i = 0; for (; i < base.ModuleAddons.Count; i++) { ChatMessage = (ChatMessagePacket)base.ModuleAddons.ElementAt(i).Value(pt, ModuleAddons.ElementAt(i).Key, ref _pReader, (PacketHandler)ChatMessage, ref _client); } } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message + " Source:" + e.Source + " Method:" + e.TargetSite + " Data:" + e.Data); } if (ChatMessage.MessageSent == null || ChatMessage.MessageSent == "") { ChatMessage.BuildPacket(); _client.SendPacket((PacketHandler)ChatMessage, _client.id, ref _client, false, false); } else { ChatMessage.BuildPacket(); _client.SendPacket((PacketHandler)ChatMessage, _client.id, ref _client, false, false); } } else { ChatMessage.MessageSent = _client._player.name + ": " + message; ChatMessage.BuildPacket(); ClientManager[] player = GridServer.player_list; for (int i = 0; i < player.Length; i++) { if (player[i] == null) { } else { if (player[i] == null) { } else { player[i].SendPacket((PacketHandler)ChatMessage, player[i].id, ref player[i], false, false); } } } } }