Esempio n. 1
0
    private void HandlePlayerJoin(string incomingUserID, string incomingUsername)
    {
        //If joining is not allowed then tell user and exit
        if (!joinAllowed)
        {
            TwitchChatClient.Instance.SendChatMessageTargeted(incomingUsername, "Joining the minigame is not currently allowed!");
            return;
        }

        //Add the user to our user list - if they are not already
        if (!joinedUsers.ContainsKey(incomingUserID))
        {
            TwitchUser user = new TwitchUser(incomingUserID, incomingUsername);
            joinedUsers.Add(incomingUserID, user);

            //Tell the user that we have added them
            TwitchChatClient.Instance.SendChatMessageTargeted(incomingUsername, "You have been added to the game!");
            PlayerJoin?.Invoke(incomingUsername);

            //We just added a new user, check if we have reached our max player count if we have then stop new joins
            if (joinedUsers.Count == maxPlayersInList)
            {
                SetAllowJoin(false, "Max players reached");
            }
        }
    }
Esempio n. 2
0
        public void Datahandle(byte[] bytes)
        {
            BaseNetObject bno = NetBaseTool.BytesToObject(bytes) as BaseNetObject;

            if (bno is SystemNetObject)
            {
                SystemNetObject systemNetObject = bno as SystemNetObject;
                if (systemNetObject.GetType() == typeof(Msg))
                {
                    Console.WriteLine(systemNetObject);
                }
                else if (systemNetObject.GetType() == typeof(GetMyUserData))
                {
                    MyUserData = (systemNetObject as GetMyUserData).userData;
                }
                else if (systemNetObject.GetType() == typeof(CreateRoomS2C))
                {
                    transmit = (systemNetObject as CreateRoomS2C).PlayerId;
                    wait.Set();
                }
                else if (systemNetObject.GetType() == typeof(JoinRoomS2C))
                {
                    transmit = (systemNetObject as JoinRoomS2C);
                    wait.Set();
                }
                else if (systemNetObject.GetType() == typeof(GetRoomListS2C))
                {
                    transmit = (systemNetObject as GetRoomListS2C).rooms;
                    wait.Set();
                }
                else if (systemNetObject.GetType() == typeof(PlayerJoinS2C))
                {
                    PlayerJoin?.Invoke((systemNetObject as PlayerJoinS2C).playerId);
                }
                else if (systemNetObject.GetType() == typeof(PlayerLeaveS2C))
                {
                    PlayerLeave?.Invoke((systemNetObject as PlayerLeaveS2C).playerId);
                }
                else if (systemNetObject.GetType() == typeof(GameStart))
                {
                    StartAction?.Invoke();
                }
            }
            else
            {
                GameNetObject gno = bno as GameNetObject;
                if (gno == null)
                {
                    throw new ArgumentException(bno.GetType() + " Can't Used");
                }
                ReceiveAction?.Invoke(gno);
            }
            //防止死锁
            // wait.Set();
        }
 public static void OnPlayerJoin(PlayerJoinEventArgs args)
 {
     PlayerJoin?.Invoke(args);
 }
Esempio n. 4
0
 public void AddPlayer(Player player)
 {
     _players.Add(player);
     PlayerJoin?.Invoke(player);
 }