public Task <bool> HandleJoinServer(JoinServerRequest request) { joinServerTaskCompletionSource = new TaskCompletionSource <bool>(); StartClient(); joinedServer = netClient.Connect(request.EndPoint.Address.ToString(), request.EndPoint.Port, "BunnyLand"); return(joinServerTaskCompletionSource.Task); }
private void AcceptClient(JoinServerRequest request) { Server.Instance.joinedPlayers.Add(agent); agent.nickname = request.nickname; agent.playerId = Server.Instance.GetNextPlayerId(); agent.connection.Send(JoinServerResponse.MakeAccept(agent.playerId)); }
public void On(JoinServerRequest request) { if (request.originConnection != agent.connection) { return; } if (RejectIfNeeded(request)) { return; } AcceptClient(request); agent.fsm.ChangeState <ServerPlayerStateInLobby>(); }
private bool RejectIfNeeded(JoinServerRequest request) { if (!request.GetIsValid()) { agent.connection.Send(JoinServerResponse.MakeReject("Invalid JoinServerRequest")); agent.Kick(); return(true); } Debug.Log("Valid client handshake received."); if (Server.Instance.joinedPlayers.Any(p => p.nickname == request.nickname)) { agent.connection.Send(JoinServerResponse.MakeReject($"Username {request.nickname} is already taken")); agent.Kick(); return(true); } return(false); }