private void AddUserVariable(string variable) { UserVariable userVariable; try { //parse json info to variable userVariable = JsonConvert.DeserializeObject <UserVariable>(variable); } catch { Console.WriteLine("Error Parsing user Variable"); return; } //if variable exists, will be changed for (int i = 0; i < userVariables.Count; i++) { if (userVariables[i].name == userVariable.name) { userVariables[i] = new UserVariable() { name = userVariable.name, value = userVariable.value }; Console.WriteLine("Added UserVar for user ID : " + id + "\n"); Console.WriteLine("User var Name :" + userVariable.name + "\n" + " Value :" + userVariable.value + "\n"); if (room.RoomName != "" || room.RoomName != null) { updateClients?.Invoke(room); onClientChangeVar?.Invoke(room, id, userVariable); } return; } } //if not exist, add to user variables. userVariables.Add(userVariable); Console.WriteLine("Added UserVar for user ID : " + id + "\n"); Console.WriteLine("User var Name :" + userVariable.name + "\n" + " Value :" + userVariable.value + "\n"); onClientChangeVar?.Invoke(room, id, userVariable); if (room.RoomName != "" || room.RoomName != null) { updateClients?.Invoke(room); } }
private void TriggerVariableChange(Room room, int _clientID, UserVariable _varName) { if (room.RoomName == null || room.RoomName == "") { return; } EventTrigger eventTrigger = new EventTrigger() { _event = ResultEvent.VariableChange, eventResultResponse = JsonConvert.SerializeObject(new VarChanged() { var = _varName, clientID = _clientID }) }; foreach (Client player in room.clientsInRoom) { player.SendEventResult(eventTrigger); } }