public static void Init(ICharacter currentCharacter) { Reset(); isInitialized = true; if (currentCharacter is null) { return; } ClientCurrentCharacterHelper.Init(currentCharacter); InitCallback?.Invoke(currentCharacter); if (currentCharacter.ProtoCharacter == Api.GetProtoEntity <PlayerCharacter>() || currentCharacter.ProtoCharacter == Api.GetProtoEntity <PlayerCharacterSpectator>() || currentCharacter.ProtoCharacter == Api.GetProtoEntity <PlayerCharacterMob>()) { InitGameplayMode(currentCharacter); } CreativeModeSystem.ClientRequestCurrentUserIsInCreativeMode(); ServerOperatorSystem.ClientRequestCurrentUserIsOperator(); InitEndCallback?.Invoke(currentCharacter); }
/// <summary> /// Initializes the string table. /// </summary> public void Initialize(INetManager network, InitCallback callback = null) { Debug.Assert(!_initialized); _callback = callback; _network = network; _network.RegisterNetMessage <MsgStringTableEntries>(MsgStringTableEntries.NAME, message => { if (_network.IsServer) // Server does not receive entries from clients. { return; } var msg = (MsgStringTableEntries)message; foreach (var entry in msg.Entries) { var id = entry.Id; var str = string.IsNullOrEmpty(entry.String) ? null : entry.String; if (str == null) { _strings.Remove(id); } else { if (TryFindStringId(str, out int oldId)) { if (oldId == id) { continue; } _strings.Remove(oldId); _strings.Add(id, str); } else { _strings.Add(id, str); } } } if (callback == null) { return; } if (_network.IsClient && !_initialized) { _callback?.Invoke(); } }); Reset(); }
private void ReceiveEntries(MsgStringTableEntries message) { DebugTools.Assert(_network.IsClient); Logger.InfoS("net", $"Received message name string table."); foreach (var entry in message.Entries) { var id = entry.Id; var str = string.IsNullOrEmpty(entry.String) ? null : entry.String; if (str == null) { _strings.Remove(id); } else { if (TryFindStringId(str, out int oldId)) { if (oldId == id) { continue; } _strings.Remove(oldId); _strings.Add(id, str); } else { _strings.Add(id, str); } } } if (_callback == null) { return; } if (_network.IsClient && !_initialized) { _callback?.Invoke(); } _updateCallback?.Invoke(message.Entries); }