public void PlayerConnect(PlayerConnectEvent eventargs) { if (InvokeRequired) { BeginInvoke((MethodInvoker)delegate { PlayerConnect(eventargs); }); return; } lstPlayers.AddIfNotExist(eventargs.getPlayer().getDisplayColor().getColor(), eventargs.getPlayer().getName()); }
static void ClassicServer_OnPlayerConnectionChanged(object sender, PlayerConnectionEventArgs e) { Event args = null; if (e.ConnectionState == LibMinecraft.Classic.Server.ConnectionState.Connected) args = new PlayerConnectEvent(e.Client); if (e.ConnectionState == LibMinecraft.Classic.Server.ConnectionState.Disconnected) args = new PlayerDisconnectEvent(e.Client); EventCache.Call(args); }
/// <summary> /// Callback method for when a player connects to the server. /// </summary> /// <param name="playerConnect">The PlayerConnect packet data.</param> private void OnPlayerConnect(PlayerConnect playerConnect) { Logger.Get().Info(this, $"Received PlayerConnect data for ID: {playerConnect.Id}"); var playerData = new ClientPlayerData(playerConnect.Id, playerConnect.Username); _playerData[playerConnect.Id] = playerData; UiManager.InternalChatBox.AddMessage($"Player '{playerConnect.Username}' connected to the server"); try { PlayerConnectEvent?.Invoke(playerData); } catch (Exception e) { Logger.Get().Warn(this, $"Exception thrown while invoking PlayerConnect event, {e.GetType()}, {e.Message}, {e.StackTrace}"); } }
/// <summary> /// Callback method for when HelloServer data is received from a client. /// </summary> /// <param name="id">The ID of the client.</param> /// <param name="helloServer">The HelloServer packet data.</param> private void OnHelloServer(ushort id, HelloServer helloServer) { Logger.Get().Info(this, $"Received HelloServer data from ID {id}"); // Start by sending the new client the current Server Settings _netServer.GetUpdateManagerForClient(id)?.UpdateGameSettings(GameSettings); if (!_playerData.TryGetValue(id, out var playerData)) { Logger.Get().Warn(this, $"Could not find player data for ID: {id}"); return; } playerData.CurrentScene = helloServer.SceneName; playerData.Position = helloServer.Position; playerData.Scale = helloServer.Scale; playerData.AnimationId = helloServer.AnimationClipId; var clientInfo = new List <(ushort, string)>(); foreach (var idPlayerDataPair in _playerData.GetCopy()) { if (idPlayerDataPair.Key == id) { continue; } clientInfo.Add((idPlayerDataPair.Key, idPlayerDataPair.Value.Username)); _netServer.GetUpdateManagerForClient(idPlayerDataPair.Key)?.AddPlayerConnectData( id, helloServer.Username ); } _netServer.GetUpdateManagerForClient(id).SetHelloClientData(clientInfo); try { PlayerConnectEvent?.Invoke(playerData); } catch (Exception e) { Logger.Get().Warn(this, $"Exception thrown while invoking PlayerConnect event, {e.GetType()}, {e.Message}, {e.StackTrace}"); } OnClientEnterScene(playerData); }
private void OnPlayerConnect(PlayerConnectEvent eventdata) { eventdata.Player.HideDialogs(); this.logger.LogInformation($"Player {eventdata.Player.Name} connected"); }