Exemple #1
0
    private void sendHumanMessage(HumanUser user, string message)
    {
        HumanUser partner = user.Partner;

        if (partner != null)
        {
            Clients.Caller.onMessageReceived(message, true);
            Clients.Client(partner.ConnectionId).onMessageReceived(message, false);
        }
    }
Exemple #2
0
    private void FindHumanPartner(HumanUser user)
    {
        HumanUser partner = (HumanUser)ConnectedUsers
                            .Find(x => x is HumanUser && x != user && ((HumanUser)x).Partner == null);

        if (partner != null)
        {
            user.Partner    = partner;
            partner.Partner = user;
            Clients.Caller.onPartnerJoined();
            Clients.Client(partner.ConnectionId).onPartnerJoined();
        }
    }
Exemple #3
0
    private User CreateNewUser(string connId, int siteId)
    {
        User newUser;

        if (FlipCoin())
        {
            newUser = new BotUser(connId, siteId);
        }
        else
        {
            newUser = new HumanUser(connId, siteId);
        }

        return(newUser);
    }
Exemple #4
0
    public void GuessPartnerIsHuman()
    {
        User user = GetCurrentUser();

        if (user != null)
        {
            if (user is HumanUser)
            {
                HumanUser humanUser = (HumanUser)user;
                ChangeHumanRank(humanUser.Partner, Constants.HUMAN_RANK_CHANGE);
                Win(user);
            }
            else if (user is BotUser)
            {
                Lose(user);
            }
        }
    }
Exemple #5
0
    public override Task OnDisconnected(bool stopCalled)
    {
        User user = GetCurrentUser();

        if (user != null)
        {
            if (user is HumanUser)
            {
                HumanUser partner = ((HumanUser)user).Partner;
                if (partner != null)
                {
                    Clients.Client(partner.ConnectionId).onPartnerLeft();
                }
            }
            ConnectedUsers.Remove(user);
        }

        return(base.OnDisconnected(stopCalled));
    }