private void CheckIncomingMessages() { NetIncomingMessage msg = netClient.ReadMessage(); if (msg != null) { string message = msg.ReadString(); if (message.Contains(":")) { string[] split = message.Split(':'); if (split[0] == "PUD") { Program.Map.mapSpriteOffset = new Vector2f(Convert.ToInt32(split[1]), Convert.ToInt32(split[2])); Program.Map.Alpha = 255; return; } } Program.CConsole.PureText.Add(message); Program.CConsole.WriteLine(message); } }
public void GotMessage() { NetIncomingMessage message; Console.Write(""); message = client.ReadMessage(); if (message != null) { switch (message.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)message.ReadByte(); Console.WriteLine("Status changed to " + status.ToString()); break; case NetIncomingMessageType.Data: { var data = message.ReadString(); Console.WriteLine(data); if (data == "exit") { //TODO: exit later } break; } default: Console.WriteLine("Unhandled message type: {message.MessageType}"); break; } } }
public static void Update(Game1 game) { while ((incmsg = Client.ReadMessage()) != null) { string header = incmsg.ReadString(); switch (header) { case "connect": { float timer = incmsg.ReadFloat(); GameLobby.timer = timer; } break; case "CharacterSelection": { string username = incmsg.ReadString(); string selectedChar = incmsg.ReadString(); int x = incmsg.ReadInt32(); int y = incmsg.ReadInt32(); if (selectedChar == "Ironman") { Player.players.Add(new Player(username, new Vector2(x, y), Game1.ironManTexture, Game1.healthTexture, new Rectangle(0, 0, 32, 48))); } else if (selectedChar == "Starlord") { Player.players.Add(new Player(username, new Vector2(x, y), Game1.starlordTexture, Game1.healthTexture, new Rectangle(0, 0, 32, 48))); } else if (selectedChar == "America") { Player.players.Add(new Player(username, new Vector2(x, y), Game1.captainAmericaTexture, Game1.healthTexture, new Rectangle(0, 0, 32, 48))); } else { Player.players.Add(new Player(username, new Vector2(x, y), Game1.warmachineTexture, Game1.healthTexture, new Rectangle(0, 0, 32, 48))); } for (int a = 0; a < Player.players.Count; a++) { for (int b = 0; b < Player.players.Count; b++) { if (a != b && Player.players[a].name.Equals(Player.players[b].name)) { Player.players.RemoveAt(a); a--; break; } } } } break; case "move": { try { string username = incmsg.ReadString(); float x = incmsg.ReadInt32(); float y = incmsg.ReadInt32(); string direction = incmsg.ReadString(); for (int i = 0; i < Player.players.Count; i++) { if (Player.players[i].name.Equals(username) && Player.players[i].name != Login.userName) { Player.players[i].playerSprite.Location = new Vector2(x, y); Player.players[i].playerSprite.direction = direction; break; } } } catch { continue; } } break; case "health": { string username = incmsg.ReadString(); float health = incmsg.ReadFloat(); for (int i = 0; i < Player.players.Count; i++) { if (Player.players[i].name == username) { Player.players[i].currentHealth = health; } } } break; case "chat": string chatItem = incmsg.ReadString(); ChatManager.chatList.Add(new ChatItem(chatItem)); ChatManager.chatStrings.Add(chatItem); break; case "newshot": { string playername = incmsg.ReadString(); float posX = incmsg.ReadFloat(); float posY = incmsg.ReadFloat(); float velocityX = incmsg.ReadFloat(); float velocityY = incmsg.ReadFloat(); float damage = incmsg.ReadFloat(); string selectedChar = incmsg.ReadString(); ShotManager.AddBullet(playername, new Vector2(posX, posY), new Vector2(velocityX, velocityY), damage, selectedChar); break; } } Client.Recycle(incmsg); } }