private void HandleMessage(IMessage aMessage) { if (DMPPluginHandler.FireOnMessageReceived(aMessage)) { return; } try { Trigger(aMessage); } catch { //DarkLog.Debug("Error handling " + typeof(aMessage).ToString() + " from " + client.playerName + ", exception: " + e); m_server.Kick(aMessage.ConnectionId, "Server failed to process " + aMessage.GetType().ToString() + " message"); } }
internal static void HandleMessage(ClientObject client, ClientMessage message) { //Prevent plugins from dodging SPLIT_MESSAGE. If they are modified, every split message will be broken. if (message.type != ClientMessageType.SPLIT_MESSAGE) { DMPPluginHandler.FireOnMessageReceived(client, message); if (message.handled) { //a plugin has handled this message and requested suppression of the default DMP behavior return; } } //Clients can only send HEARTBEATS, HANDSHAKE_REQUEST or CONNECTION_END's until they are authenticated. if (!client.authenticated && !(message.type == ClientMessageType.HEARTBEAT || message.type == ClientMessageType.HANDSHAKE_RESPONSE || message.type == ClientMessageType.CONNECTION_END)) { Messages.ConnectionEnd.SendConnectionEnd(client, "You must authenticate before attempting to send a " + message.type.ToString() + " message"); return; } #if !DEBUG try { #endif switch (message.type) { case ClientMessageType.HEARTBEAT: //Don't do anything for heartbeats, they just keep the connection alive break; case ClientMessageType.HANDSHAKE_RESPONSE: Messages.Handshake.HandleHandshakeResponse(client, message.data); break; case ClientMessageType.CHAT_MESSAGE: Messages.Chat.HandleChatMessage(client, message.data); break; case ClientMessageType.PLAYER_STATUS: Messages.PlayerStatus.HandlePlayerStatus(client, message.data); break; case ClientMessageType.PLAYER_COLOR: Messages.PlayerColor.HandlePlayerColor(client, message.data); break; case ClientMessageType.GROUP: Messages.GroupMessage.HandleMessage(client, message.data); break; case ClientMessageType.SCENARIO_DATA: Messages.ScenarioData.HandleScenarioModuleData(client, message.data); break; case ClientMessageType.SYNC_TIME_REQUEST: Messages.SyncTimeRequest.HandleSyncTimeRequest(client, message.data); break; case ClientMessageType.KERBALS_REQUEST: Messages.KerbalsRequest.HandleKerbalsRequest(client); break; case ClientMessageType.KERBAL_PROTO: Messages.KerbalProto.HandleKerbalProto(client, message.data); break; case ClientMessageType.VESSELS_REQUEST: Messages.VesselRequest.HandleVesselsRequest(client, message.data); break; case ClientMessageType.VESSEL_PROTO: Messages.VesselProto.HandleVesselProto(client, message.data); break; case ClientMessageType.VESSEL_UPDATE: Messages.VesselUpdate.HandleVesselUpdate(client, message.data); break; case ClientMessageType.VESSEL_REMOVE: Messages.VesselRemove.HandleVesselRemoval(client, message.data); break; case ClientMessageType.PERMISSION: Messages.PermissionMessage.HandleMessage(client, message.data); break; case ClientMessageType.CRAFT_LIBRARY: Messages.CraftLibrary.HandleCraftLibrary(client, message.data); break; case ClientMessageType.SCREENSHOT_LIBRARY: Messages.ScreenshotLibrary.HandleScreenshotLibrary(client, message.data); break; case ClientMessageType.FLAG_SYNC: Messages.FlagSync.HandleFlagSync(client, message.data); break; case ClientMessageType.PING_REQUEST: Messages.PingRequest.HandlePingRequest(client, message.data); break; case ClientMessageType.MOTD_REQUEST: Messages.MotdRequest.HandleMotdRequest(client); break; case ClientMessageType.WARP_CONTROL: Messages.WarpControl.HandleWarpControl(client, message.data); break; case ClientMessageType.LOCK_SYSTEM: Messages.LockSystem.HandleLockSystemMessage(client, message.data); break; case ClientMessageType.MOD_DATA: Messages.ModData.HandleModDataMessage(client, message.data); break; case ClientMessageType.KERBAL_REMOVE: Messages.VesselRemove.HandleKerbalRemoval(client, message.data); break; case ClientMessageType.SPLIT_MESSAGE: Messages.SplitMessage.HandleSplitMessage(client, message.data); break; case ClientMessageType.CONNECTION_END: Messages.ConnectionEnd.HandleConnectionEnd(client, message.data); break; case ClientMessageType.MODPACK_DATA: Messages.Modpack.HandleModpackMessage(client, message.data); break; default: DarkLog.Debug("Unhandled message type " + message.type); Messages.ConnectionEnd.SendConnectionEnd(client, "Unhandled message type " + message.type); #if DEBUG throw new NotImplementedException("Message type not implemented"); #else break; #endif } #if !DEBUG } catch (Exception e) { DarkLog.Debug("Error handling " + message.type + " from " + client.playerName + ", exception: " + e); Messages.ConnectionEnd.SendConnectionEnd(client, "Server failed to process " + message.type + " message"); } #endif }