Esempio n. 1
0
        public static void ListAllClients(string json)
        {
            List <ClientInfo> clients = JsonHelper.GetClientsInfo(json);

            foreach (ClientInfo client in clients)
            {
                // Invalid client
                if (!client.id.IsValid)
                {
                    continue;
                }

                // Ignore ourself
                if (client.id.value == GlobalState.networkUser.id)
                {
                    continue;
                }

                if (client.room.IsValid)
                {
                    // Only consider clients in our room
                    if (client.room.value != GlobalState.networkUser.room)
                    {
                        continue;
                    }

                    // Retrieve the viewId (one of possible - required to send data)
                    MixerUser player = (MixerUser)GlobalState.networkUser;
                    if (client.viewId.IsValid && null == player.viewId)
                    {
                        player.viewId = client.viewId.value;
                    }

                    // Add client to the list of connected users in our room
                    if (!GlobalState.HasConnectedUser(client.id.value))
                    {
                        MixerUser newUser = new MixerUser
                        {
                            id = client.id.value
                        };
                        if (client.userName.IsValid)
                        {
                            newUser.name = client.userName.value;
                        }
                        if (client.userColor.IsValid)
                        {
                            newUser.color = client.userColor.value;
                        }
                        if (client.eye.IsValid)
                        {
                            newUser.position = client.eye.value;
                        }
                        if (client.target.IsValid)
                        {
                            newUser.target = client.target.value;
                        }
                        GlobalState.AddConnectedUser(newUser);
                    }
                }
            }
        }
Esempio n. 2
0
 public static string CreateClientNameAndColor()
 {
     return(JsonHelper.CreateJsonClientNameAndColor(GlobalState.networkUser.name, GlobalState.networkUser.color));
 }
Esempio n. 3
0
        public static void UpdateClient(string json)
        {
            ClientInfo client = JsonHelper.GetClientInfo(json);

            if (client.id.IsValid)
            {
                // Ignore info on ourself
                if (client.id.value == GlobalState.networkUser.id)
                {
                    return;
                }

                if (client.room.IsValid)
                {
                    // A client may leave the room
                    if (client.room.value == "null")
                    {
                        GlobalState.RemoveConnectedUser(client.id.value);
                        return;
                    }

                    // Ignore other room messages
                    if (client.room.value != GlobalState.networkUser.room)
                    {
                        return;
                    }

                    // Add client to the list of connected users in our room
                    if (!GlobalState.HasConnectedUser(client.id.value))
                    {
                        MixerUser newUser = new MixerUser
                        {
                            id = client.id.value
                        };
                        GlobalState.AddConnectedUser(newUser);
                    }
                }

                // Get client connected to our room
                if (!GlobalState.HasConnectedUser(client.id.value))
                {
                    return;
                }
                MixerUser user = (MixerUser)GlobalState.GetConnectedUser(client.id.value);

                // Retrieve the viewId (one of possible - required to send data)
                MixerUser player = (MixerUser)GlobalState.networkUser;
                if (client.viewId.IsValid && null == player.viewId)
                {
                    player.viewId = client.viewId.value;
                }

                if (client.userName.IsValid)
                {
                    user.name = client.userName.value;
                }
                if (client.userColor.IsValid)
                {
                    user.color = client.userColor.value;
                }

                bool changed = false;

                // Get its eye position
                if (client.eye.IsValid)
                {
                    user.position = client.eye.value;
                    changed       = true;
                }

                // Get its target look at
                if (client.target.IsValid)
                {
                    user.target = client.target.value;
                    changed     = true;
                }

                if (changed)
                {
                    GlobalState.UpdateConnectedUser(user);
                }
            }
        }
Esempio n. 4
0
 public static string CreateJsonPlayerInfo(MixerUser playerInfo)
 {
     return(JsonHelper.CreateJsonPlayerInfo(playerInfo));
 }