private void NetworkManagerMessageArrived(object sender, IncomingNetworkMessageArgs args) { NetIncomingMessage message = args.Message; switch (message.MessageType) { case NetIncomingMessageType.StatusChanged: var statMsg = (NetConnectionStatus)message.ReadByte(); if (statMsg == NetConnectionStatus.Disconnected) { string disconnectMessage = message.ReadString(); UserInterfaceManager.AddComponent(new DisconnectedScreenBlocker(StateManager, UserInterfaceManager, ResourceManager, disconnectMessage)); } break; case NetIncomingMessageType.Data: var messageType = (NetMessage)message.ReadByte(); switch (messageType) { case NetMessage.LobbyChat: string text = message.ReadString(); AddChat(text); break; case NetMessage.PlayerCount: //TODO var newCount = message.ReadByte(); break; case NetMessage.PlayerList: HandlePlayerList(message); break; case NetMessage.WelcomeMessage: HandleWelcomeMessage(message); break; case NetMessage.ChatMessage: HandleChatMessage(message); break; case NetMessage.JobList: HandleJobList(message); break; case NetMessage.JobSelected: HandleJobSelected(message); break; case NetMessage.JoinGame: HandleJoinGame(); break; } break; } }
void netMgr_MessageArrived(object sender, IncomingNetworkMessageArgs e) { //Make sure we reset the position - we might recieve this message after the gamestates. if (e.Message.Position > 0) e.Message.Position = 0; if (e.Message.MessageType == NetIncomingMessageType.Data && (NetMessage)e.Message.PeekByte() == NetMessage.ConsoleCommandReply) { e.Message.ReadByte(); AddLine("Server: " + e.Message.ReadString(), Color.RoyalBlue); } //Again, make sure we reset the position - we might get it before the gamestate and then that would break. e.Message.Position = 0; }
private void NetMgr_MessageArrived(object sender, IncomingNetworkMessageArgs e) { //Make sure we reset the position - we might recieve this message after the gamestates. if (e.Message.Position > 0) { e.Message.Position = 0; } if (e.Message.MessageType != NetIncomingMessageType.Data) { return; } switch ((NetMessage)e.Message.PeekByte()) { case NetMessage.ConsoleCommandReply: e.Message.ReadByte(); AddLine("< " + e.Message.ReadString(), new Color(65, 105, 225)); break; case NetMessage.ConsoleCommandRegister: e.Message.ReadByte(); for (ushort amount = e.Message.ReadUInt16(); amount > 0; amount--) { string commandName = e.Message.ReadString(); // Do not do duplicate commands. if (commands.ContainsKey(commandName)) { AddLine("Server sent console command {0}, but we already have one with the same name. Ignoring." + commandName, Color.White); continue; } string description = e.Message.ReadString(); string help = e.Message.ReadString(); var command = new ServerDummyCommand(commandName, help, description); commands[commandName] = command; } break; } //Again, make sure we reset the position - we might get it before the gamestate and then that would break. e.Message.Position = 0; }