void HandleClientMessage(NetIncomingMessage msg) { MessageFunction type = (MessageFunction)msg.ReadInt32(); switch (type) { case MessageFunction.ClassMessage: string assemblyName = msg.ReadString(); string classType = msg.ReadString(); Message report = (Message)Activator.CreateInstance(assemblyName, classType).Unwrap(); msg.ReadAllFields(report); report.OnCalled(report, msg); break; case MessageFunction.SpawnAllPlayer: int count = msg.ReadInt32(); for (int i = 0; i < count; i++) { int id = msg.ReadInt32(); string playerName = msg.ReadString(); SpawnPlayer(id, playerName); } int newId = SpawnLocalPlayer(); MessageSpawnPlayer spawnMessage = new MessageSpawnPlayer(); spawnMessage.playerId = newId; spawnMessage.playerName = PlatformService.personaName; SendNetworkMessage(spawnMessage, SendTo.Others); break; case MessageFunction.UpdateVehiclesPositions: m_vNetworkManager.UpdateCarsPositions(msg); break; case MessageFunction.RemoveVehicle: int carID2 = msg.ReadInt32(); m_vNetworkManager.RemoveCar(carID2); break; case MessageFunction.UpdateCitizensPositions: m_cNetworkManager.UpdateCitizensPositions(msg); break; default: Debug.LogWarning("Unhandled msg type: " + type.ToString()); break; } }
void HandleClientMessage(NetIncomingMessage msg) { MessageFunction type = (MessageFunction)msg.ReadInt32(); switch (type) { case MessageFunction.ClassMessage: string assemblyName = msg.ReadString(); string classType = msg.ReadString(); Message report = (Message)Activator.CreateInstance(assemblyName, classType).Unwrap(); msg.ReadAllFields(report); report.OnCalled(report, msg); break; case MessageFunction.SpawnAllPlayer: int count = msg.ReadInt32(); for (int i = 0; i < count; i++) { int id = msg.ReadInt32(); string playerName = msg.ReadString(); SpawnPlayer(id, playerName); } int newId = SpawnLocalPlayer(); MessageSpawnPlayer spawnMessage = new MessageSpawnPlayer(); spawnMessage.playerId = newId; spawnMessage.playerName = Steam.personaName; SendNetworkMessage(spawnMessage, SendTo.Others); break; case MessageFunction.UpdateVehiclesPositions: m_vNetworkManager.UpdateCarsPositions(msg); break; case MessageFunction.RemoveVehicle: int carID2 = msg.ReadInt32(); m_vNetworkManager.RemoveCar(carID2); break; case MessageFunction.UpdateCitizensPositions: m_cNetworkManager.UpdateCitizensPositions(msg); break; default: Debug.LogWarning("Unhandled msg type: " + type.ToString()); break; } }
public override void OnCalled(Message msg, NetIncomingMessage netMsg = null) { MessageSpawnPlayer message = msg as MessageSpawnPlayer; MultiplayerManager.instance.SpawnPlayer(message.playerId, message.playerName, netMsg.SenderConnection); }