public void ChangeAuth(object dispatcher) { while (true) { if (config.idSession == null || config.AvatarAddress == null) { Thread.Sleep(500); continue; } var client = new WebClient(); client.DownloadFileTaskAsync(config.AvatarAddress, "avatar.jpg").Wait(); ((Dispatcher)dispatcher).BeginInvoke(new Action(() => { Image img = new Image(); BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new Uri(Environment.CurrentDirectory + "/avatar.jpg", UriKind.Absolute); src.EndInit(); img.Source = src; img.Stretch = System.Windows.Media.Stretch.Uniform; config.AvatarImage = img; AvatarChange.Invoke(); })); break; } }
private static void OnAllianceUpdateAvatarDataMessageReceived(AllianceAvatarChangesMessage message) { if (AllianceManager.TryGet(message.AccountId, out Alliance alliance) && alliance.Members.TryGetValue(message.MemberId, out AllianceMemberEntry memberEntry)) { bool updateScoring = false; for (int i = 0; i < message.AvatarChanges.Size(); i++) { AvatarChange avatarChange = message.AvatarChanges[i]; avatarChange.ApplyAvatarChange(memberEntry); if (avatarChange.GetAvatarChangeType() == AvatarChangeType.SCORE || avatarChange.GetAvatarChangeType() == AvatarChangeType.DUEL_SCORE) { updateScoring = true; } } AllianceSession currentSession = alliance.GetCurrentOnlineMemberSession(message.MemberId); if (currentSession != null && currentSession.LogicClientAvatar != null) { for (int i = 0; i < message.AvatarChanges.Size(); i++) { message.AvatarChanges[i].ApplyAvatarChange(currentSession.LogicClientAvatar); } } if (updateScoring) { alliance.UpdateScoring(); } AllianceManager.Save(alliance); } }
AvatarChange ParseAvatarChange(string line, int offset, string dataCode) { string json = line.Substring(offset); json = json.Replace("{{", "{").Replace("}}", "}"); var jsonDoc = JsonDocument.Parse(json); AvatarChange avc = new AvatarChange(); try { JsonElement twoFiftyOne = jsonDoc.RootElement .GetProperty("Parameters") .GetProperty(dataCode); JsonElement user = twoFiftyOne.GetProperty("user"); JsonElement jsonOut; if (twoFiftyOne.TryGetProperty("steamUserID", out jsonOut)) { avc.steamID = jsonOut.GetString(); } if (twoFiftyOne.TryGetProperty("avatarVariations", out jsonOut)) { avc.avatarID = jsonOut.GetString(); } avc.displayName = user.GetProperty("displayName").GetString(); avc.userID = user.GetProperty("id").GetString(); avc.avatarCloning = user.GetProperty("allowAvatarCopying").GetBoolean(); if (twoFiftyOne.TryGetProperty("inVRMode", out jsonOut)) { avc.inVRMode = jsonOut.GetBoolean(); } JsonElement avatarDict; if (twoFiftyOne.TryGetProperty("avatarDict", out avatarDict)) { if (avc.avatarID == null && avatarDict.TryGetProperty("id", out jsonOut)) { avc.avatarID = jsonOut.GetString(); } if (avatarDict.TryGetProperty("name", out jsonOut)) { avc.avatarName = jsonOut.GetString(); } if (avatarDict.TryGetProperty("description", out jsonOut)) { avc.avatarDescription = jsonOut.GetString(); } if (avatarDict.TryGetProperty("authorName", out jsonOut)) { avc.avatarAuthor = jsonOut.GetString(); } if (avatarDict.TryGetProperty("authorId", out jsonOut)) { avc.avatarAuthorUserID = jsonOut.GetString(); } } /* * public string modTag; * public string statusDescription; */ } catch (Exception e) { Console.Write("Error parsing avatar change!"); } return(avc); }