public void Run(Server server, NetIncomingMessage im, PlayerAndConnection playerAndConnection, GameMap gameMap) { Console.WriteLine("New connection attempt..."); var data = im.ReadByte(); if (data == (byte)PacketType.Login) { Console.WriteLine(" .. approved."); // Create the player and add it to the map var packetData = new LoginPacketIO().ReadRequest(im); playerAndConnection = CreatePlayer(im, packetData.Username, gameMap); // Create the hail message // it contains the player id and all the players already connected var hmsg = CreateHailMessage(server, playerAndConnection, gameMap); im.SenderConnection.Approve(hmsg); // Add the player to the map gameMap.AddPlayer(playerAndConnection); server.SendNewPlayerBroadcast(playerAndConnection); } else { im.SenderConnection.Deny("Bad packet"); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { managerLogger.AddLogMessage("Create", "Received ability"); var name = inc.ReadString(); Byte ID = inc.ReadByte(); var ability = CreateAbility(name, ID, inc); abilities.Add(ability); //Send ability to all the clients... var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.AbilityCreate); outmsg.Write(ability.Username); outmsg.Write(ability.ID); outmsg.Write((byte)ability.Type); outmsg.Write(ability.XPosition); outmsg.Write(ability.YPosition); outmsg.Write(ability.Direction); outmsg.Write(ability.Damage); managerLogger.AddLogMessage("Create", " sending ability to all clients"); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { managerLogger.AddLogMessage("Server", "New connection..."); var data = inc.ReadByte(); if (data == (byte)PacketType.Login) { managerLogger.AddLogMessage("Server", "...connection accepted"); playerAndConnection = CreatePlayer(inc, players); inc.SenderConnection.Approve(); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.Login); outmsg.Write(true); outmsg.Write(players.Count); for (int n = 0; n < players.Count; n++) { outmsg.WriteAllProperties(players[n].Player); } server.NetServer.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0); var command = new PlayerPositionCommand(); command.Run(managerLogger, server, inc, playerAndConnection, players, abilities); server.SendNewPlayerEvent(playerAndConnection.Player.Username); } else { inc.SenderConnection.Deny("Didn't send correct information."); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", "New connection..."); var data = inc.ReadByte(); if (data == (byte)PacketType.Login) { managerLogger.AddLogMessage("server", "..connection accpeted."); playerAndConnection = CreatePlayer(inc, gameRoom.Players, gameRoom.ManagerCamera); inc.SenderConnection.Approve(); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.Login); outmsg.Write(true); outmsg.Write(gameRoom.Players.Count); for (int n = 0; n < gameRoom.Players.Count; n++) { var p = gameRoom.Players[n]; outmsg.Write(p.Player.Username); outmsg.WriteAllProperties(p.Player.Position); } server.NetServer.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0); var command = new PlayerPositionCommand(); command.Run(managerLogger, server,inc,playerAndConnection,gameRoom); server.SendNewPlayerEvent(playerAndConnection.Player.Username, gameRoom.GameRoomId); } else { inc.SenderConnection.Deny("Didn't send correct information."); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server",string.Format("Kicking {0}",playerAndConnection.Player.Username)); var outmessage = server.NetServer.CreateMessage(); outmessage.Write((byte)PacketType.Kick); outmessage.Write(playerAndConnection.Player.Username); server.NetServer.SendToAll(outmessage, NetDeliveryMethod.ReliableOrdered); //Kick player playerAndConnection.Connection.Disconnect("Bye bye, you're kicked."); }
public void Run(Server server, NetIncomingMessage im, PlayerAndConnection playerAndConnection, GameMap gameMap) { var playerData = new UpdatePlayerPositionPacketIO().ReadResponse(im).Player; var player = gameMap.Players.FirstOrDefault(p => p.Player.Id == playerData.Id); if (player != null) { player.Player = playerData; } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", "Received new input"); var key = (Keys)inc.ReadByte(); var name = inc.ReadString(); playerAndConnection = gameRoom.Players.FirstOrDefault(p => p.Player.Username == name); if (playerAndConnection == null) { managerLogger.AddLogMessage("server", string.Format("Could not find player with name {0}", name)); return; } int x = 0; int y = 0; switch (key) { case Keys.Down: y++; break; case Keys.Up: y--; break; case Keys.Left: x--; break; case Keys.Right: x++; break; } var player = playerAndConnection.Player; var position = playerAndConnection.Player.Position; if (!ManagerCollision.CheckCollision(new Rectangle(position.XPosition + x, position.YPosition + y, 100, 50), player.Username, gameRoom.Players.Select(p => p.Player).ToList())) { position.XPosition += x; position.YPosition += y; position.Visible = gameRoom.ManagerCamera.InScreenCheck(new Vector2(position.XPosition, position.YPosition)); if (position.Visible) { var screenPosition = gameRoom.ManagerCamera.WorldToScreenPosition(new Vector2(position.XPosition, position.YPosition)); position.ScreenXPosition = (int) screenPosition.X; position.ScreenYPosition = (int) screenPosition.Y; } var command = new PlayerPositionCommand(); command.Run(managerLogger, server, inc, playerAndConnection, gameRoom); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { if (playerAndConnection != null) { managerLogger.AddLogMessage("server", "Sending out new player position to all in group " + gameRoom.GameRoomId); var outmessage = server.NetServer.CreateMessage(); outmessage.Write((byte) PacketType.PlayerPosition); outmessage.WriteAllProperties(playerAndConnection.Player); server.NetServer.SendMessage(outmessage, gameRoom.Players.Select(p => p.Connection).ToList(), NetDeliveryMethod.ReliableOrdered, 0); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { int seed = Server.random.Next(1000); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.Seed); outmsg.Write(seed); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); server.NetServer.FlushSendQueue(); }
public void Run(Server server, NetIncomingMessage im, PlayerAndConnection playerAndConnection, GameMap gameMap) { var msg = server.CreateMessage(); var data = new AllPlayersPacketIO.PacketDataResponse { Players = gameMap.Players.Select(p => p.Player).ToArray() }; new AllPlayersPacketIO().WriteResponse(msg, data); var connections = gameMap.Players.Select(x => x.Connection).ToList(); server.NetServer.SendMessage(msg, connections, NetDeliveryMethod.ReliableOrdered, 0); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", "Sending full player list"); var outmessage = server.NetServer.CreateMessage(); outmessage.Write((byte)PacketType.AllPlayers); outmessage.Write(CameraUpdate); outmessage.Write(gameRoom.Players.Count); foreach (var p in gameRoom.Players) { outmessage.WriteAllProperties(p.Player); } server.NetServer.SendMessage(outmessage, gameRoom.Players.Select(p => p.Connection).ToList(), NetDeliveryMethod.ReliableOrdered, 0); }
public void Run(Server server, NetIncomingMessage im, PlayerAndConnection playerAndConnection, GameMap gameMap) { if (playerAndConnection != null) { var msg = server.NetServer.CreateMessage(); msg.Write((byte)PacketType.PlayerPosition); msg.Write(playerAndConnection.Player.Id); msg.Write(playerAndConnection.Player.PositionX); msg.Write(playerAndConnection.Player.PositionY); server.NetServer.SendMessage(msg, gameMap.Players.Select(x => x.Connection).ToList(), NetDeliveryMethod.ReliableOrdered, 0); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { managerLogger.AddLogMessage("Update", "Received ability"); var name = inc.ReadString(); Byte ID = inc.ReadByte(); var ability = ReadAbility(inc, abilities, ID, name); if (ability != null) { SendAbility(server, ability, managerLogger); } }
private PlayerAndConnection CreatePlayer(NetIncomingMessage im, string username, GameMap gameMap) { var rand = new Random(); var player = new PlayerData { Id = gameMap.GeneratePlayerId(), Username = username, PositionX = rand.Next(400), PositionY = 0 }; var playerAndConnection = new PlayerAndConnection(player, im.SenderConnection); return(playerAndConnection); }
private PlayerAndConnection CreatePlayer(NetIncomingMessage inc, List <PlayerAndConnection> players) { var random = new Random(); var player = new Player { Username = inc.ReadString(), Type = (Player.ClassType)inc.ReadByte(), XPosition = (short)random.Next(0, 750), YPosition = (short)random.Next(0, 400) }; var playerAndConnection = new PlayerAndConnection(player, inc.SenderConnection); players.Add(playerAndConnection); return(playerAndConnection); }
private PlayerAndConnection CreatePlayer(NetIncomingMessage inc, List<PlayerAndConnection> players, ManagerCamera managerCamera) { var random = new Random(); var player = new Player { Username = inc.ReadString(), Position = new Position {XPosition = random.Next(0, 750), YPosition = random.Next(0, 420) } }; var playerVectorPosition = new Vector2(player.Position.XPosition, player.Position.YPosition); var screenPosition = managerCamera.WorldToScreenPosition(playerVectorPosition); player.Position.ScreenXPosition = (int) screenPosition.X; player.Position.ScreenYPosition = (int) screenPosition.Y; player.Position.Visible = managerCamera.InScreenCheck(playerVectorPosition); var playerAndConnection = new PlayerAndConnection(player, inc.SenderConnection); players.Add(playerAndConnection); return playerAndConnection; }
private NetOutgoingMessage CreateHailMessage(Server server, PlayerAndConnection playerAndConnection, GameMap gameMap) { var otherPlayers = gameMap.Players.Select(p => p.Player).ToArray(); foreach (var player in otherPlayers) { Console.WriteLine($"{player.Id} - {player.PositionX} - {player.PositionY}"); } var data = new LoginPacketIO.PacketDataResponse { Player = playerAndConnection.Player, OtherPlayers = otherPlayers }; var hmsg = server.NetServer.CreateMessage(); new LoginPacketIO().WriteResponse(hmsg, data); return(hmsg); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.PlayerPosition); outmsg.Write(playerAndConnection.Player.Username); outmsg.Write(playerAndConnection.Player.XPosition); outmsg.Write(playerAndConnection.Player.YPosition); outmsg.Write(playerAndConnection.Player.Animation.XRecPos); outmsg.Write(playerAndConnection.Player.Animation.YRecPos); outmsg.Write(playerAndConnection.Player.Animation.Height); outmsg.Write(playerAndConnection.Player.Animation.Width); outmsg.Write(playerAndConnection.Player.Health); outmsg.Write(playerAndConnection.Player.IntersectingLava); outmsg.Write((byte)playerAndConnection.Player.Type); outmsg.Write(playerAndConnection.Player.OrbiterRotation); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); }
private PlayerAndConnection CreatePlayer(NetConnection connection, string userName) { var player = new Player { Username = userName }; #if DEBUG player.Characters.Add(new Character("Aerith", EnumCharacterModel.MODEL_1)); player.Characters.Add(new Character("Nanaki", EnumCharacterModel.MODEL_6)); player.Characters.Add(new Character("Vincent", EnumCharacterModel.MODEL_8)); player.Characters.Add(new Character("Barett", EnumCharacterModel.MODEL_2)); player.Characters.Add(new Character("Tifa", EnumCharacterModel.MODEL_7)); player.Characters.Add(new Character("Youffie", EnumCharacterModel.MODEL_9)); #else #endif var playerAndConnection = new PlayerAndConnection(player, connection); //players.Add(playerAndConnection); return(playerAndConnection); }
private PlayerAndConnection CreatePlayer(NetIncomingMessage inc, List <PlayerAndConnection> players, ManagerCamera managerCamera) { var random = new Random(); var player = new Player { Username = inc.ReadString(), Position = new Position { XPosition = random.Next(0, 750), YPosition = random.Next(0, 420) } }; var playerVectorPosition = new Vector2(player.Position.XPosition, player.Position.YPosition); var screenPosition = managerCamera.WorldToScreenPosition(playerVectorPosition); player.Position.ScreenXPosition = (int)screenPosition.X; player.Position.ScreenYPosition = (int)screenPosition.Y; player.Position.Visible = managerCamera.InScreenCheck(playerVectorPosition); var playerAndConnection = new PlayerAndConnection(player, inc.SenderConnection); players.Add(playerAndConnection); return(playerAndConnection); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { managerLogger.AddLogMessage("Class Change", "Recieved a class change"); string name = inc.ReadString(); var player = players.FirstOrDefault(p => p.Player.Username == name); if (player == null) { managerLogger.AddLogMessage("Class Change", "Didnt find a player associated with that name"); } player.Player.Type = (ClassType)inc.ReadByte(); managerLogger.AddLogMessage("Class Change", "Class type succesfully changed"); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.ClassChange); outmsg.Write(name); outmsg.Write((byte)player.Player.Type); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { string name = inc.ReadString(); bool ready = inc.ReadBoolean(); managerLogger.AddLogMessage("Ready", "Recieved ready check"); var player = players.FirstOrDefault(p => p.Player.Username == name); player.Player.Ready = ready; var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.ReadyCheck); outmsg.Write(name); outmsg.Write(ready); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); server.NetServer.FlushSendQueue(); bool allReady = true; for (int i = 0; i < players.Count; i++) { if (!players[i].Player.Ready) { allReady = false; } } if (allReady) { RandomSeedCommand randomSeedCommand = new RandomSeedCommand(); randomSeedCommand.Run(managerLogger, server, inc, playerAndConnection, players, abilities); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { managerLogger.AddLogMessage("Deletion", "Received ability to delete"); string username = inc.ReadString(); byte ID = inc.ReadByte(); for (int i = 0; i < abilities.Count; i++) { if (abilities[i].ID == ID && abilities[i].Username == username) { abilities.RemoveAt(i); i--; managerLogger.AddLogMessage("Deletion", "Sending ability to delete to clients"); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.AbilityDelete); outmsg.Write(username); outmsg.Write(ID); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); } } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", "New connection..."); var data = inc.ReadByte(); if (data == (byte)PacketType.Login) { inc.SenderConnection.Approve(); managerLogger.AddLogMessage("server", "..connection accpeted."); playerAndConnection = CreatePlayer(inc, gameRoom.Players, gameRoom.ManagerCamera); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.Login); outmsg.Write(gameRoom.Players.Count); for (int n = 0; n < gameRoom.Players.Count; n++) { var p = gameRoom.Players[n]; outmsg.Write(p.Player.Username); outmsg.WriteAllProperties(p.Player.Position); } server.NetServer.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0); var command = new PlayerPositionCommand(); command.Run(managerLogger, server, inc, playerAndConnection, gameRoom); server.SendNewPlayerEvent(playerAndConnection.Player.Username, gameRoom.GameRoomId); } else { inc.SenderConnection.Deny("Didn't send correct information."); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, List <PlayerAndConnection> players, List <AbilityOutline> abilities) { managerLogger.AddLogMessage("Score", "Recieved score"); string name = inc.ReadString(); playerAndConnection = players.FirstOrDefault(p => p.Player.Username == name); if (playerAndConnection == null) { return; } playerAndConnection.Player.Score++; managerLogger.AddLogMessage("Score", "Sending out score"); var outmsg = server.NetServer.CreateMessage(); outmsg.Write((byte)PacketType.Score); outmsg.Write(playerAndConnection.Player.Username); outmsg.Write(playerAndConnection.Player.Score); server.NetServer.SendToAll(outmsg, NetDeliveryMethod.ReliableOrdered); //whenver a player gets score it is a new round meaning that now a new seed should be sent!!! RandomSeedCommand command = new RandomSeedCommand(); command.Run(managerLogger, server, inc, playerAndConnection, players, abilities); }
private string GetPlayerName(PlayerAndConnection conn) { return("[" + conn.Id + "] " + conn.Player.Username + " (" + (conn.Latency < 1.0 ? (conn.Latency * 1000).ToString("0.0000") + " ms" : conn.Latency.ToString("0.0000") + " s") + ")"); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", string.Format("Kicking {0}", playerAndConnection.Player.Username)); var outmessage = server.NetServer.CreateMessage(); outmessage.Write((byte)PacketType.Kick); outmessage.Write(playerAndConnection.Player.Username); server.NetServer.SendToAll(outmessage, NetDeliveryMethod.ReliableOrdered); //Kick player playerAndConnection.Connection.Disconnect("Bye bye, you're kicked."); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", "Sending full player list"); var outmessage = server.NetServer.CreateMessage(); outmessage.Write((byte)PacketType.AllPlayers); outmessage.Write(CameraUpdate); outmessage.Write(gameRoom.Players.Count); foreach (var p in gameRoom.Players) { outmessage.Write(p.Player.Username); outmessage.WriteAllProperties(p.Player.Position); } server.NetServer.SendMessage(outmessage, gameRoom.Players.Select(p => p.Connection).ToList(), NetDeliveryMethod.ReliableOrdered, 0); }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { managerLogger.AddLogMessage("server", "Received new input"); var key = (Keys)inc.ReadByte(); var name = inc.ReadString(); playerAndConnection = gameRoom.Players.FirstOrDefault(p => p.Player.Username == name); if (playerAndConnection == null) { managerLogger.AddLogMessage("server", string.Format("Could not find player with name {0}", name)); return; } int x = 0; int y = 0; switch (key) { case Keys.Down: y++; break; case Keys.Up: y--; break; case Keys.Left: x--; break; case Keys.Right: x++; break; } var player = playerAndConnection.Player; var position = playerAndConnection.Player.Position; if (!ManagerCollision.CheckCollision(new Rectangle(position.XPosition + x, position.YPosition + y, 100, 50), player.Username, gameRoom.Players.Select(p => p.Player).ToList())) { position.XPosition += x; position.YPosition += y; position.Visible = gameRoom.ManagerCamera.InScreenCheck(new Vector2(position.XPosition, position.YPosition)); if (position.Visible) { var screenPosition = gameRoom.ManagerCamera.WorldToScreenPosition(new Vector2(position.XPosition, position.YPosition)); position.ScreenXPosition = (int)screenPosition.X; position.ScreenYPosition = (int)screenPosition.Y; } var command = new PlayerPositionCommand(); command.Run(managerLogger, server, inc, playerAndConnection, gameRoom); } }
public void Run(ManagerLogger managerLogger, Server server, NetIncomingMessage inc, PlayerAndConnection playerAndConnection, GameRoom gameRoom) { if (playerAndConnection != null) { managerLogger.AddLogMessage("server", "Sending out new player position to all in group " + gameRoom.GameRoomId); var outmessage = server.NetServer.CreateMessage(); outmessage.Write((byte)PacketType.PlayerPosition); outmessage.Write(playerAndConnection.Player.Username); outmessage.WriteAllProperties(playerAndConnection.Player.Position); server.NetServer.SendMessage(outmessage, gameRoom.Players.Select(p => p.Connection).ToList(), NetDeliveryMethod.ReliableOrdered, 0); } }