// The client needs to do the sending to the server, because with reliability turned on, it needs to send all the commands until the server acks them public void SendCommandToServer(JUMPCommand c) { RaiseEventOptions options = new RaiseEventOptions(); options.Receivers = ReceiverGroup.MasterClient; if (IsOfflinePlayMode) { // There is only one server in the offline scenario, let's call it directly! JUMPMultiplayer.GameServer.OnPhotonEventCall(c.CommandEventCode, c.CommandData, JUMPMultiplayer.PlayerID); } else { // Let's go via networking PhotonNetwork.RaiseEvent(c.CommandEventCode, c.CommandData, true, options); } }
// Server Engine internal void OnPhotonEventCall(byte eventCode, object content, int senderId) { // We are the server, hence, we are only processing events for the Master Client if (IsOfflinePlayMode || PhotonNetwork.isMasterClient) { if (eventCode == JUMPCommand_Connect.JUMPCommand_Connect_EventCode) { JUMPCommand_Connect c = new JUMPCommand_Connect((object[])content); // Set the player as connected JUMPPlayer player = new JUMPPlayer(); player.PlayerID = c.PlayerID; player.IsConnected = true; Players.Add(player); int maxPlayerId = player.PlayerID; // Add bots as players if offline if (IsOfflinePlayMode) { Bots.ForEach(x => { x.PlayerID = ++maxPlayerId; x.IsConnected = true; Players.Add(x); }); } int connectedplayers = Players.Count(p => p.IsConnected); // When all the players are connected, start the game. if (connectedplayers == JUMPOptions.NumPlayers) { GameServerEngine.StartGame(Players); } } else { JUMPCommand c = GameServerEngine.CommandFromEvent(eventCode, content); if (c != null) { GameServerEngine.ProcessCommand(c); } } } }