/// <summary> /// Handles all actions for recieving data messages (Such as movement, block placing, etc) /// </summary> /// <param name="inc">The incoming message</param> private void ProcessDataMessage(NetIncomingMessage inc) { // The type of message being recieved var type = (MessageTypes)Enum.Parse(typeof(MessageTypes), inc.ReadByte().ToString()); // The user who sent the message var sender = Server.PlayerFromRUI(inc.SenderConnection.RemoteUniqueIdentifier); if (sender != null) { switch (type) { // If the user requests a message to be sent, send it back case MessageTypes.Request: { var msg = new RequestMessage(inc, MessageContext.Server); Server.Events.Network.MessageRequested.Invoke( new EventManager.NetEvents.RequestMessageEventArgs(msg.Type, sender)); break; } case MessageTypes.CreateLevel: { var msg = new CreateLevelMessage(inc, MessageContext.Server); Server.Events.Network.CreateLevelMessageRecieved.Invoke( new EventManager.NetEvents.CreateLevelEventArgs(sender, msg.Name, msg.Description)); break; } case MessageTypes.JoinLevel: { var msg = new JoinLevelMessage(inc, MessageContext.Server); Server.Events.Network.JoinLevelMessageRecieved.Invoke( new EventManager.NetEvents.JoinLevelEventArgs(sender, msg.UUID)); break; } case MessageTypes.Chat: { var msg = new ChatMessage(inc, MessageContext.Server); Server.Events.Network.ChatMessageReceived.Invoke(new EventManager.NetEvents.ChatEventArgs( sender, msg.Message)); break; } case MessageTypes.BlockPlace: { var msg = new BlockPlaceMessage(inc, MessageContext.Server); Server.Events.Network.BlockPlaceMessageReceived.Invoke( new EventManager.NetEvents.BlockPlacedEventArgs(sender, msg.Point.X, msg.Point.Y, msg.Layer, msg.Type)); break; } } } }
/// <summary> /// Handles a data message (The bulk of all messages received, containing player movements, block places, etc) /// </summary> private void HandleDataMessage(NetIncomingMessage im) { if (im == null) { throw new ArgumentNullException(nameof(im)); } var type = (MessageTypes)im.ReadByte(); switch (type) { case MessageTypes.Init: { var msg = new InitMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.InitReceived.Invoke( new EventManager.NetEvents.GameServerEvents.InitEventArgs(msg)); break; } case MessageTypes.Banner: { var msg = new BannerMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.LobbyBannerReceived.Invoke( new EventManager.NetEvents.GameServerEvents.BannerEventArgs(msg.Banner)); break; } case MessageTypes.LevelData: { var msg = new LevelDataMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.LevelDataReceived.Invoke( new EventManager.NetEvents.GameServerEvents.LevelDataEventArgs(new Level(msg.Level, networkManager.Client))); break; } case MessageTypes.Chat: { var msg = new ChatMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.ChatReceived.Invoke( new EventManager.NetEvents.GameServerEvents.ChatEventArgs(msg.Message)); break; } case MessageTypes.PlayerJoin: { var msg = new PlayerJoinMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.PlayerJoinReceived.Invoke( new EventManager.NetEvents.GameServerEvents.PlayerJoinEventArgs(msg.Player)); break; } case MessageTypes.PingUpdate: { var msg = new PingUpdateMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.PingUpdateReceived.Invoke( new EventManager.NetEvents.GameServerEvents.PingUpdateEventArgs(msg.Pings)); break; } case MessageTypes.BlockPlace: { if (networkManager.Client.Level != null) { var msg = new BlockPlaceMessage(im, MessageContext.Client); networkManager.Client.Events.Network.Game.BlockPlaceMessageReceived.Invoke( new EventManager.NetEvents.GameServerEvents.BlockPlacedEventArgs(networkManager.Client.Level, msg.Point.X, msg.Point.Y, msg.Layer, msg.Type)); } break; } } }