public MyPlayer CreateNewPlayer(MyIdentity identity, PlayerId id, string playerName) { Debug.Assert(Sync.IsServer); MyNetworkClient steamClient; Sync.Clients.TryGetClient(id.SteamId, out steamClient); Debug.Assert(steamClient != null, "Could not find a client for the new player!"); if (steamClient == null) return null; var player = CreateNewPlayerInternal(identity, steamClient, playerName, ref id); if (player != null) { var msg = new PlayerCreatedMsg(); msg.ClientSteamId = id.SteamId; msg.PlayerSerialId = id.SerialId; msg.IdentityId = identity.IdentityId; msg.DisplayName = playerName; Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); } return player; }
static void OnPlayerCreated(ref PlayerCreatedMsg msg, MyNetworkClient sender) { var identity = Sync.Players.TryGetIdentity(msg.IdentityId); Debug.Assert(identity != null, "Identity for the new player not found!"); if (identity == null) return; MyNetworkClient client = null; Sync.Clients.TryGetClient(msg.ClientSteamId, out client); Debug.Assert(client != null, "Could not find client of the new player!"); if (client == null) return; var playerId = new MyPlayer.PlayerId(msg.ClientSteamId, msg.PlayerSerialId); var playerBuilder = new MyObjectBuilder_Player(); playerBuilder.DisplayName = msg.DisplayName; playerBuilder.IdentityId = msg.IdentityId; playerBuilder.BuildColorSlots = msg.BuildColors; Sync.Players.CreateNewPlayerInternal(client, playerId, playerBuilder); }
static void OnPlayerCreated(ref PlayerCreatedMsg msg, MyNetworkClient sender) { var identity = Sync.Players.TryGetIdentity(msg.IdentityId); Debug.Assert(identity != null, "Identity for the new player not found!"); if (identity == null) return; MyNetworkClient client = null; Sync.Clients.TryGetClient(msg.ClientSteamId, out client); Debug.Assert(client != null, "Could not find client of the new player!"); var playerId = new MyPlayer.PlayerId(msg.ClientSteamId, msg.PlayerSerialId); Sync.Players.CreateNewPlayerInternal(identity, client, msg.DisplayName, ref playerId); }
public MyPlayer CreateNewPlayer(MyIdentity identity, PlayerId id, string playerName) { Debug.Assert(Sync.IsServer); MyNetworkClient steamClient; Sync.Clients.TryGetClient(id.SteamId, out steamClient); Debug.Assert(steamClient != null, "Could not find a client for the new player!"); if (steamClient == null) return null; var playerBuilder = new MyObjectBuilder_Player(); playerBuilder.DisplayName = playerName; playerBuilder.IdentityId = identity.IdentityId; var player = CreateNewPlayerInternal(steamClient, id, playerBuilder); if (player != null) { var msg = new PlayerCreatedMsg(); msg.ClientSteamId = id.SteamId; msg.PlayerSerialId = id.SerialId; msg.IdentityId = identity.IdentityId; msg.DisplayName = playerName; msg.BuildColors = null; if (!MyPlayer.IsColorsSetToDefaults(player.BuildColorSlots)) msg.BuildColors = player.BuildColorSlots; Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); } return player; }