/// <summary> /// Broadcasts a message to all players in a room, EXCEPT for the one specified /// </summary> /// <param name="gameMessage">IMessage to send</param> /// <param name="player">Player NOT to send to</param> public void BroadcastExcept(IMessage gameMessage, Player player) { BroadcastExcept(gameMessage, (NetConnection)NetServer.Connections.Where(x => x.RemoteUniqueIdentifier == player.RUI && Server.PlayerFromRUI(x.RemoteUniqueIdentifier, true).Map.ID == player.Map.ID) .ElementAt(0)); }
public PlayerStateMessage(Player player) { this.ID = player.ID; this.Position = player.SimulationState.Position.ToPoint(); this.Velocity = player.SimulationState.Velocity.ToPoint(); this.Movement = player.SimulationState.Movement.ToPoint(); this.MessageTime = NetTime.Now; }
public PlayerModeMessage(Player player) { this.Mode = player.Mode; this.ID = player.ID; this.MessageTime = NetTime.Now; }
public ChatMessage(Player player,string message) { this.ID = player.ID; this.Message = message; this.MessageTime = NetTime.Now; }
public PlayerSmileyMessage(Player player, SmileyType smiley) { this.ID = player.ID; this.Smiley = smiley; }
/// <summary> /// Handles a data message (The bulk of all messages recieved, containing player movements, block places, etc) /// </summary> private void HandleDataMessage(NetIncomingMessage im) { MessageTypes messageType = (MessageTypes)im.ReadByte(); //Find the type of data message sent switch (messageType) { case MessageTypes.Lobby: //Lobby list packet { if (Game.CurrentGameState == GameState.Lobby) { LobbyScreen screen = MainWindow.ScreenManager.Current as LobbyScreen; LobbyMessage msg = new LobbyMessage(im); screen.Name = msg.ServerName; screen.Description = msg.Description; screen.Intro = msg.Intro; screen.Online = msg.Online; screen.Rooms = msg.Rooms; screen.Lobby.LoadRooms(); } break; } case MessageTypes.PlayerJoin: //Player join message { PlayerJoinMessage user = new PlayerJoinMessage(im); //Add player to map Map.Players.Add(new Player(Map, Map.Spawn, user.Username, user.ID) { Tint = user.Color }); //Add user to userlist (MainWindow.ScreenManager.Current as GameScreen).PlayerList.Items.Add(user.Username); if (user.ID != Game.MyID && recievedInit) //Broadcast join message to chat { (MainWindow.ScreenManager.Current as GameScreen).SystemChat(user.Username + " [color:LightGray]has[/color] [color:LightGreen]joined.[/color]"); } if (user.Me) { //Let game know of it's own player Game.MyID = user.ID; Game.MyIndex = (byte)Map.Players.IndexOf(Map.Players.First(x => x.ID == Game.MyID)); Game.Me.Tint = Game.MyColor; } break; } case MessageTypes.PlayerLeave: //Player leave message { PlayerLeaveMessage user = new PlayerLeaveMessage(im); //Remove player if (user.ID != Game.MyID) { Player player = (Player)Map.PlayerFromID(user.ID); Map.Players.Remove((Player)Map.PlayerFromID(user.ID)); (MainWindow.ScreenManager.Current as GameScreen).PlayerList.Items.Remove(player.Username); (MainWindow.ScreenManager.Current as GameScreen).SystemChat(player.Username + " [color:LightGray]has[/color] [color:IndianRed]left.[/color]"); //Rebuild indexes for (int i = 0; i < Map.Players.Count; i++) { Map.Players[i].Index = i; if (Map.Players[i].ID == Game.MyID) { Game.MyIndex = (byte)i; } } } break; } case MessageTypes.PlayerStatus: //Player move message { if (Game.CurrentGameState == GameState.Game) { PlayerStateMessage user = new PlayerStateMessage(im); Player player = (Player)Map.PlayerFromID(user.ID); player.SimulationState.Position = user.Position.ToVector2(); player.SimulationState.Velocity = user.Velocity.ToVector2(); player.SimulationState.Movement = user.Movement.ToVector2(); if (!recievedInit) //If we have not recieved init (meaning we are not in game yet), set the initial positions directly so interpolation doesn't mess with them { player.DisplayState.Position = player.SimulationState.Position; } player.VirtualJump = user.IsJumping; } break; } case MessageTypes.Block: //Block place message { if (Game.CurrentGameState == GameState.Game) { BlockMessage msg = new BlockMessage(im); BlockType block = BlockType.FromID(msg.BlockID); if (Map.CanPlaceBlock(msg.X, msg.Y, msg.Z, block)) { Map.Tiles[msg.X, msg.Y, msg.Z].Block = block; } } break; } case MessageTypes.PlayerSmiley: //Smiley change message { if (Game.CurrentGameState == GameState.Game) { PlayerSmileyMessage msg = new PlayerSmileyMessage(im); Player p = (Player)Map.PlayerFromID(msg.ID); p.Smiley = msg.Smiley; } break; } case MessageTypes.PlayerMode: //Player mode change message { if (Game.CurrentGameState == GameState.Game) { PlayerModeMessage mode = new PlayerModeMessage(im); Map.PlayerFromID(mode.ID).Mode = (PlayerMode)mode.Mode; } break; } case MessageTypes.Chat: //Chat message { if (Game.CurrentGameState == GameState.Game) { ChatMessage chat = new ChatMessage(im); (MainWindow.ScreenManager.Current as GameScreen).AddChat(Map.PlayerFromID(chat.ID).Username, chat.Message); } break; } case MessageTypes.Init: //Initialization message with world data { Game.Map = new Bricklayer.Client.World.Map(game, 1, 1); InitMessage msg = new InitMessage(im, Map); Game.Map.Minimap = new Minimap(Game.Map, msg.Width, msg.Height) { Position = new Microsoft.Xna.Framework.Vector2(8, 8) }; Game.Map.CreateCamera(); Game.CurrentGameState = GameState.Game; (MainWindow.ScreenManager.Current as GameScreen).Show(); (MainWindow.ScreenManager.Current as GameScreen).SystemChat("Connected to [color:LightGray]" + Game.Host + ":" + Game.Port + "[/color]"); recievedInit = true; break; } } }