예제 #1
0
 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);
 }
예제 #2
0
    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));
    }
예제 #3
0
    public void On(JoinServerRequest request)
    {
        if (request.originConnection != agent.connection)
        {
            return;
        }
        if (RejectIfNeeded(request))
        {
            return;
        }

        AcceptClient(request);
        agent.fsm.ChangeState <ServerPlayerStateInLobby>();
    }
예제 #4
0
    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);
    }