internal static bool CheckValid(ValidateAuthTicketResponse_t r) { ESteamRejection?reason = null; if (OnJoinRequested != null) { foreach (var handler in OnJoinRequested.GetInvocationList().Cast <JoinRequested>()) { try { handler(r.m_SteamID, ref reason); if (reason != null) { Provider.Reject(r.m_SteamID, reason.Value); return(false); } } catch (Exception ex) { Logger.LogException(ex); } } } return(true); }
internal static void CheckValid(ValidateAuthTicketResponse_t r, ref bool isValid, ref string explain) { if (!isValid) { return; } ESteamRejection?reason = null; try { var playerGroups = R.Permissions.GetGroups(new RocketPlayer(r.m_SteamID.ToString()), true); string prefix = playerGroups.FirstOrDefault(x => !string.IsNullOrEmpty(x.Prefix))?.Prefix; string suffix = playerGroups.FirstOrDefault(x => !string.IsNullOrEmpty(x.Suffix))?.Suffix; if (prefix != null || suffix != null) { SteamPending steamPending = Provider.pending.FirstOrDefault(x => x.playerID.steamID == r.m_SteamID); if (steamPending != null) { if (prefix != null && !steamPending.playerID.characterName.StartsWith(prefix)) { steamPending.playerID.characterName = $"{prefix}{steamPending.playerID.characterName}"; } if (suffix != null && !steamPending.playerID.characterName.EndsWith(suffix)) { steamPending.playerID.characterName = $"{steamPending.playerID.characterName}{suffix}"; } } } } catch (Exception ex) { Core.Logging.Logger.Log($"Failed adding prefix/suffix to player {r.m_SteamID}: {ex}"); } if (OnJoinRequested != null) { foreach (var handler in OnJoinRequested.GetInvocationList()) { try { ((JoinRequested)handler)(r.m_SteamID, ref reason); if (reason != null) { Provider.reject(r.m_SteamID, reason.Value); isValid = false; return; } } catch (Exception ex) { Core.Logging.Logger.LogException(ex); } } } return; }
internal static bool CheckValid(ValidateAuthTicketResponse_t r) { ESteamRejection?reason = null; try { IOrderedEnumerable <RocketPermissionsGroup> playerGroups = R.Permissions.GetGroups(new RocketPlayer(r.m_SteamID.ToString()), true).OrderBy(x => x.Priority); string prefix = playerGroups.FirstOrDefault(x => x.Prefix != null)?.Prefix ?? ""; string suffix = playerGroups.FirstOrDefault(x => x.Suffix != null)?.Suffix ?? ""; if (prefix != "" || suffix != "") { SteamPending steamPending = Provider.pending.FirstOrDefault(x => x.playerID.steamID == r.m_SteamID); if (steamPending != null) { if (prefix != "" && !steamPending.playerID.characterName.StartsWith(prefix)) { steamPending.playerID.characterName = $"{prefix}{steamPending.playerID.characterName}"; } if (suffix != "" && !steamPending.playerID.characterName.EndsWith(suffix)) { steamPending.playerID.characterName = $"{steamPending.playerID.characterName}{suffix}"; } } } } catch (Exception ex) { Core.Logging.Logger.Log($"Failed adding prefix/suffix to player {r.m_SteamID}: {ex}"); } if (OnJoinRequested != null) { foreach (var handler in OnJoinRequested.GetInvocationList().Cast <JoinRequested>()) { try { handler(r.m_SteamID, ref reason); if (reason != null) { Provider.reject(r.m_SteamID, reason.Value); return(false); } } catch (Exception ex) { Core.Logging.Logger.LogException(ex); } } } return(true); }
internal static bool CheckValid(ValidateAuthTicketResponse_t r) { ESteamRejection?reason = null; try { RocketPermissionsGroup g = R.Permissions.GetGroups(new Rocket.API.RocketPlayer(r.m_SteamID.ToString()), true).FirstOrDefault(); if (g != null) { SteamPending steamPending = Provider.pending.FirstOrDefault(x => x.playerID.steamID == r.m_SteamID); if (steamPending != null) { string prefix = g.Prefix ?? ""; string suffix = g.Suffix ?? ""; if (prefix != "" && !steamPending.playerID.characterName.StartsWith(g.Prefix)) { steamPending.playerID.characterName = prefix + steamPending.playerID.characterName; } if (suffix != "" && !steamPending.playerID.characterName.EndsWith(g.Suffix)) { steamPending.playerID.characterName = steamPending.playerID.characterName + suffix; } } } } catch (Exception ex) { Core.Logging.Logger.Log("Failed adding prefix/suffix to player " + r.m_SteamID + ": " + ex.ToString()); } if (OnJoinRequested != null) { foreach (var handler in OnJoinRequested.GetInvocationList().Cast <JoinRequested>()) { try { handler(r.m_SteamID, ref reason); if (reason != null) { Provider.reject(r.m_SteamID, reason.Value); return(false); } } catch (Exception ex) { Core.Logging.Logger.LogException(ex); } } } return(true); }
/// <summary> /// Processes the message, updating our internal state and then invokes the events. /// </summary> /// <param name="message"></param> private void ProcessMessage(IMessage message) { if (message == null) { return; } switch (message.Type) { //We got a update, so we will update our current presence case MessageType.PresenceUpdate: lock (_sync) { PresenceMessage pm = message as PresenceMessage; if (pm != null) { //We need to merge these presences together if (CurrentPresence == null) { CurrentPresence = pm.Presence; } else if (pm.Presence == null) { CurrentPresence = null; } else { CurrentPresence.Merge(pm.Presence); } //Update the message pm.Presence = CurrentPresence; } } break; //Update our configuration case MessageType.Ready: ReadyMessage rm = message as ReadyMessage; if (rm != null) { lock (_sync) { Configuration = rm.Configuration; CurrentUser = rm.User; } //Resend our presence and subscription SynchronizeState(); } break; //Update the request's CDN for the avatar helpers case MessageType.JoinRequest: if (Configuration != null) { //Update the User object within the join request if the current Cdn JoinRequestMessage jrm = message as JoinRequestMessage; if (jrm != null) { jrm.User.SetConfiguration(Configuration); } } break; case MessageType.Subscribe: lock (_sync) { SubscribeMessage sub = message as SubscribeMessage; Subscription |= sub.Event; } break; case MessageType.Unsubscribe: lock (_sync) { UnsubscribeMessage unsub = message as UnsubscribeMessage; Subscription &= ~unsub.Event; } break; //We got a message we dont know what to do with. default: break; } //Invoke the appropriate methods switch (message.Type) { case MessageType.Ready: if (OnReady != null) { OnReady.Invoke(this, message as ReadyMessage); } break; case MessageType.Close: if (OnClose != null) { OnClose.Invoke(this, message as CloseMessage); } break; case MessageType.Error: if (OnError != null) { OnError.Invoke(this, message as ErrorMessage); } break; case MessageType.PresenceUpdate: if (OnPresenceUpdate != null) { OnPresenceUpdate.Invoke(this, message as PresenceMessage); } break; case MessageType.Subscribe: if (OnSubscribe != null) { OnSubscribe.Invoke(this, message as SubscribeMessage); } break; case MessageType.Unsubscribe: if (OnUnsubscribe != null) { OnUnsubscribe.Invoke(this, message as UnsubscribeMessage); } break; case MessageType.Join: if (OnJoin != null) { OnJoin.Invoke(this, message as JoinMessage); } break; case MessageType.Spectate: if (OnSpectate != null) { OnSpectate.Invoke(this, message as SpectateMessage); } break; case MessageType.JoinRequest: if (OnJoinRequested != null) { OnJoinRequested.Invoke(this, message as JoinRequestMessage); } break; case MessageType.ConnectionEstablished: if (OnConnectionEstablished != null) { OnConnectionEstablished.Invoke(this, message as ConnectionEstablishedMessage); } break; case MessageType.ConnectionFailed: if (OnConnectionFailed != null) { OnConnectionFailed.Invoke(this, message as ConnectionFailedMessage); } break; default: //This in theory can never happen, but its a good idea as a reminder to update this part of the library if any new messages are implemented. Logger.Error("Message was queued with no appropriate handle! {0}", message.Type); break; } }
/// <summary> /// Dequeues all the messages from Discord and invokes appropriate methods. This will process the message and update the internal state before invoking the events. Returns the messages that were invoked and in the order they were invoked. /// </summary> /// <returns>Returns the messages that were invoked and in the order they were invoked.</returns> public IMessage[] Invoke() { //Dequeue all the messages and process them IMessage[] messages = connection.DequeueMessages(); for (int i = 0; i < messages.Length; i++) { //Do a bit of pre-processing var message = messages[i]; HandleMessage(message); //Invoke the appropriate methods switch (message.Type) { case MessageType.Ready: if (OnReady != null) { OnReady.Invoke(this, message as ReadyMessage); } break; case MessageType.Close: if (OnClose != null) { OnClose.Invoke(this, message as CloseMessage); } break; case MessageType.Error: if (OnError != null) { OnError.Invoke(this, message as ErrorMessage); } break; case MessageType.PresenceUpdate: if (OnPresenceUpdate != null) { OnPresenceUpdate.Invoke(this, message as PresenceMessage); } break; case MessageType.Subscribe: if (OnSubscribe != null) { OnSubscribe.Invoke(this, message as SubscribeMessage); } break; case MessageType.Unsubscribe: if (OnUnsubscribe != null) { OnUnsubscribe.Invoke(this, message as UnsubscribeMessage); } break; case MessageType.Join: if (OnJoin != null) { OnJoin.Invoke(this, message as JoinMessage); } break; case MessageType.Spectate: if (OnSpectate != null) { OnSpectate.Invoke(this, message as SpectateMessage); } break; case MessageType.JoinRequest: if (OnJoinRequested != null) { OnJoinRequested.Invoke(this, message as JoinRequestMessage); } break; case MessageType.ConnectionEstablished: if (OnConnectionEstablished != null) { OnConnectionEstablished.Invoke(this, message as ConnectionEstablishedMessage); } break; case MessageType.ConnectionFailed: if (OnConnectionFailed != null) { OnConnectionFailed.Invoke(this, message as ConnectionFailedMessage); } break; default: //This in theory can never happen, but its a good idea as a reminder to update this part of the library if any new messages are implemented. Logger.Error("Message was queued with no appropriate handle! {0}", message.Type); break; } } //Finally, return the messages return(messages); }
public static void RunJoinRequested(CSteamID player, ref ESteamRejection?rejectionReason) => OnJoinRequested?.Invoke(player, ref rejectionReason);