Пример #1
0
 public static KeyValuePair <string, object>[] GetAllPartyAttributes(PartyId partyId)
 {
     if (partyId == null)
     {
         return(new KeyValuePair <string, object> [0]);
     }
     string[] array;
     BattleNet.GetAllPartyAttributes(partyId.ToEntityId(), out array);
     KeyValuePair <string, object>[] array2 = new KeyValuePair <string, object> [array.Length];
     for (int i = 0; i < array2.Length; i++)
     {
         string text  = array[i];
         object value = null;
         long?  partyAttributeLong = BnetParty.GetPartyAttributeLong(partyId, text);
         if (partyAttributeLong != null)
         {
             value = partyAttributeLong;
         }
         string partyAttributeString = BnetParty.GetPartyAttributeString(partyId, text);
         if (partyAttributeString != null)
         {
             value = partyAttributeString;
         }
         byte[] partyAttributeBlob = BnetParty.GetPartyAttributeBlob(partyId, text);
         if (partyAttributeBlob != null)
         {
             value = partyAttributeBlob;
         }
         array2[i] = new KeyValuePair <string, object>(text, value);
     }
     return(array2);
 }
Пример #2
0
 public static void RevokeSentInvite(PartyId partyId, ulong inviteId)
 {
     if (!BnetParty.IsInParty(partyId))
     {
         return;
     }
     BattleNet.RevokePartyInvite(partyId.ToEntityId(), inviteId);
 }
Пример #3
0
 public static void SendChatMessage(PartyId partyId, string chatMessage)
 {
     if (!BnetParty.IsInParty(partyId))
     {
         return;
     }
     BattleNet.SendPartyChatMessage(partyId.ToEntityId(), chatMessage);
 }
Пример #4
0
 public static PartyInvite GetSentInvite(PartyId partyId, ulong inviteId)
 {
     if (partyId == null)
     {
         return(null);
     }
     PartyInvite[] sentInvites = BnetParty.GetSentInvites(partyId);
     return(sentInvites.FirstOrDefault((PartyInvite i) => i.InviteId == inviteId));
 }
Пример #5
0
        public static void SetPrivacy(PartyId partyId, PrivacyLevel privacyLevel)
        {
            if (!BnetParty.IsInParty(partyId))
            {
                return;
            }
            EntityId partyId2 = partyId.ToEntityId();

            BattleNet.SetPartyPrivacy(partyId2, (int)privacyLevel);
        }
Пример #6
0
        public static bool IsMember(PartyId partyId, BnetGameAccountId memberId)
        {
            if (partyId == null)
            {
                return(false);
            }
            PartyMember member = BnetParty.GetMember(partyId, memberId);

            return(member != null);
        }
Пример #7
0
        public static void DissolveParty(PartyId partyId)
        {
            if (!BnetParty.IsInParty(partyId))
            {
                return;
            }
            EntityId partyId2 = partyId.ToEntityId();

            BattleNet.DissolveParty(partyId2);
        }
Пример #8
0
        public static void SendInvite(PartyId toWhichPartyId, BnetGameAccountId recipientId)
        {
            if (!BnetParty.IsInParty(toWhichPartyId))
            {
                return;
            }
            EntityId partyId   = toWhichPartyId.ToEntityId();
            EntityId inviteeId = BnetEntityId.CreateEntityId(recipientId);

            BattleNet.SendPartyInvite(partyId, inviteeId, false);
        }
Пример #9
0
 public static PartyMember GetMember(PartyId partyId, BnetGameAccountId memberId)
 {
     foreach (PartyMember partyMember in BnetParty.GetMembers(partyId))
     {
         if (partyMember.GameAccountId == memberId)
         {
             return(partyMember);
         }
     }
     return(null);
 }
Пример #10
0
        public static void KickMember(PartyId partyId, BnetGameAccountId memberId)
        {
            if (!BnetParty.IsInParty(partyId))
            {
                return;
            }
            EntityId partyId2  = partyId.ToEntityId();
            EntityId memberId2 = BnetEntityId.CreateEntityId(memberId);

            BattleNet.KickPartyMember(partyId2, memberId2);
        }
Пример #11
0
        public static bool IsPartyFull(PartyId partyId, bool includeInvites = true)
        {
            if (partyId == null)
            {
                return(false);
            }
            int num             = BnetParty.CountMembers(partyId);
            int num2            = (!includeInvites) ? 0 : BnetParty.GetSentInvites(partyId).Length;
            int maxPartyMembers = BattleNet.GetMaxPartyMembers(partyId.ToEntityId());

            return(num + num2 >= maxPartyMembers);
        }
Пример #12
0
        public static void SetLeader(PartyId partyId, BnetGameAccountId memberId)
        {
            if (!BnetParty.IsInParty(partyId))
            {
                return;
            }
            EntityId  partyId2     = partyId.ToEntityId();
            EntityId  memberId2    = BnetEntityId.CreateEntityId(memberId);
            PartyType partyType    = BnetParty.GetPartyType(partyId);
            uint      leaderRoleId = PartyMember.GetLeaderRoleId(partyType);

            BattleNet.AssignPartyRole(partyId2, memberId2, leaderRoleId);
        }
Пример #13
0
        public static PartyMember GetMyselfMember(PartyId partyId)
        {
            if (partyId == null)
            {
                return(null);
            }
            BnetGameAccountId bnetGameAccountId = BnetGameAccountId.CreateFromEntityId(BattleNet.GetMyGameAccountId());

            if (bnetGameAccountId == null)
            {
                return(null);
            }
            return(BnetParty.GetMember(partyId, bnetGameAccountId));
        }
Пример #14
0
        private static void RaisePartyError(bool isOperationCallback, string szPartyType, BnetFeatureEvent featureEvent, string errorMessageFormat, params object[] args)
        {
            string debugContext = string.Format(errorMessageFormat, args);

            BnetParty.RaisePartyError(new PartyError
            {
                IsOperationCallback = isOperationCallback,
                DebugContext        = debugContext,
                ErrorCode           = BattleNetErrors.ERROR_OK,
                Feature             = BnetFeature.Party,
                FeatureEvent        = featureEvent,
                szPartyType         = szPartyType
            });
        }
Пример #15
0
        public static PartyMember GetLeader(PartyId partyId)
        {
            if (partyId == null)
            {
                return(null);
            }
            PartyMember[] members   = BnetParty.GetMembers(partyId);
            PartyType     partyType = BnetParty.GetPartyType(partyId);

            foreach (PartyMember partyMember in members)
            {
                if (partyMember.IsLeader(partyType))
                {
                    return(partyMember);
                }
            }
            return(null);
        }
Пример #16
0
        public static bool IsLeader(PartyId partyId)
        {
            if (partyId == null)
            {
                return(false);
            }
            PartyMember myselfMember = BnetParty.GetMyselfMember(partyId);

            if (myselfMember != null)
            {
                PartyType partyType = BnetParty.GetPartyType(partyId);
                if (myselfMember.IsLeader(partyType))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #17
0
 private static void RaisePartyError(bool isOperationCallback, string debugContext, BattleNetErrors errorCode, BnetFeature feature, BnetFeatureEvent featureEvent, PartyId partyId, string szPartyType, string stringData, string errorMessageFormat, params object[] args)
 {
     if (BnetParty.OnError == null)
     {
         return;
     }
     BnetParty.RaisePartyError(new PartyError
     {
         IsOperationCallback = isOperationCallback,
         DebugContext        = debugContext,
         ErrorCode           = errorCode,
         Feature             = feature,
         FeatureEvent        = featureEvent,
         PartyId             = partyId,
         szPartyType         = szPartyType,
         StringData          = stringData
     });
 }
Пример #18
0
        private static void RaisePartyError(PartyError error)
        {
            string message = string.Format("BnetParty: event={0} feature={1} code={2} partyId={3} type={4} strData={5}", new object[]
            {
                error.FeatureEvent.ToString(),
                (int)error.FeatureEvent,
                error.ErrorCode,
                error.PartyId,
                error.szPartyType,
                error.StringData
            });
            LogLevel level = (!(error.ErrorCode == BattleNetErrors.ERROR_OK)) ? LogLevel.Error : LogLevel.Info;

            Log.Party.Print(level, message);
            if (BnetParty.OnError != null)
            {
                BnetParty.OnError(error);
            }
        }
Пример #19
0
        public static void CreateParty(PartyType partyType, PrivacyLevel privacyLevel, byte[] creatorBlob, BnetParty.CreateSuccessCallback successCallback)
        {
            string @string = EnumUtils.GetString <PartyType>(partyType);

            if (BnetParty.s_pendingPartyCreates != null && BnetParty.s_pendingPartyCreates.ContainsKey(partyType))
            {
                BnetParty.RaisePartyError(true, @string, BnetFeatureEvent.Party_Create_Callback, "CreateParty: Already creating party of type {0}", new object[]
                {
                    partyType
                });
                return;
            }
            if (BnetParty.s_pendingPartyCreates == null)
            {
                BnetParty.s_pendingPartyCreates = new Map <PartyType, BnetParty.CreateSuccessCallback>();
            }
            BnetParty.s_pendingPartyCreates[partyType] = successCallback;
            BattleNet.CreateParty(@string, (int)privacyLevel, creatorBlob);
        }
Пример #20
0
        public static void RequestInvite(PartyId partyId, BnetGameAccountId whomToAskForApproval, BnetGameAccountId whomToInvite, PartyType partyType)
        {
            if (BnetParty.IsLeader(partyId))
            {
                PartyError error = default(PartyError);
                error.IsOperationCallback = true;
                error.DebugContext        = "RequestInvite";
                error.ErrorCode           = BattleNetErrors.ERROR_INVALID_TARGET_ID;
                error.Feature             = BnetFeature.Party;
                error.FeatureEvent        = BnetFeatureEvent.Party_RequestPartyInvite_Callback;
                error.PartyId             = partyId;
                error.szPartyType         = EnumUtils.GetString <PartyType>(partyType);
                error.StringData          = "leaders cannot RequestInvite - use SendInvite instead.";
                BnetParty.OnError(error);
                return;
            }
            EntityId partyId2 = partyId.ToEntityId();
            EntityId whomToAskForApproval2 = BnetEntityId.CreateEntityId(whomToAskForApproval);
            EntityId whomToInvite2         = BnetEntityId.CreateEntityId(whomToInvite);
            string   @string = EnumUtils.GetString <PartyType>(partyType);

            BattleNet.RequestPartyInvite(partyId2, whomToAskForApproval2, whomToInvite2, @string);
        }
Пример #21
0
        public static void Process()
        {
            PartyListenerEvent[] array;
            BattleNet.GetPartyListenerEvents(out array);
            BattleNet.ClearPartyListenerEvents();
            int i = 0;

            while (i < array.Length)
            {
                PartyListenerEvent partyListenerEvent = array[i];
                PartyId            partyId            = partyListenerEvent.PartyId;
                switch (partyListenerEvent.Type)
                {
                case PartyListenerEventType.ERROR_RAISED:
                case PartyListenerEventType.OPERATION_CALLBACK:
                {
                    PartyError error = partyListenerEvent.ToPartyError();
                    if (error.ErrorCode != BattleNetErrors.ERROR_OK)
                    {
                        if (BnetParty.IsIgnorableError(error.FeatureEvent, error.ErrorCode.EnumVal))
                        {
                            error.ErrorCode = BattleNetErrors.ERROR_OK;
                            if (error.FeatureEvent == BnetFeatureEvent.Party_Leave_Callback)
                            {
                                if (!BnetParty.s_joinedParties.ContainsKey(partyId))
                                {
                                    BnetParty.s_joinedParties[partyId] = PartyType.SPECTATOR_PARTY;
                                }
                                goto IL_22D;
                            }
                        }
                        if (error.IsOperationCallback && error.FeatureEvent == BnetFeatureEvent.Party_Create_Callback)
                        {
                            PartyType partyType = error.PartyType;
                            if (BnetParty.s_pendingPartyCreates.ContainsKey(partyType))
                            {
                                BnetParty.s_pendingPartyCreates.Remove(partyType);
                            }
                        }
                    }
                    if (error.ErrorCode != BattleNetErrors.ERROR_OK)
                    {
                        BnetParty.RaisePartyError(error);
                    }
                    break;
                }

                case PartyListenerEventType.JOINED_PARTY:
                {
                    string    stringData          = partyListenerEvent.StringData;
                    PartyType partyTypeFromString = BnetParty.GetPartyTypeFromString(stringData);
                    BnetParty.s_joinedParties[partyId] = partyTypeFromString;
                    if (BnetParty.s_pendingPartyCreates != null)
                    {
                        BnetParty.CreateSuccessCallback createSuccessCallback = null;
                        if (BnetParty.s_pendingPartyCreates.ContainsKey(partyTypeFromString))
                        {
                            createSuccessCallback = BnetParty.s_pendingPartyCreates[partyTypeFromString];
                            BnetParty.s_pendingPartyCreates.Remove(partyTypeFromString);
                        }
                        else if (stringData == "default" && BnetParty.s_pendingPartyCreates.Count == 0)
                        {
                            createSuccessCallback = BnetParty.s_pendingPartyCreates.First <KeyValuePair <PartyType, BnetParty.CreateSuccessCallback> >().Value;
                            BnetParty.s_pendingPartyCreates.Clear();
                        }
                        if (createSuccessCallback != null)
                        {
                            createSuccessCallback(partyTypeFromString, partyId);
                        }
                    }
                    if (BnetParty.OnJoined != null)
                    {
                        BnetParty.OnJoined(OnlineEventType.ADDED, new PartyInfo(partyId, partyTypeFromString), null);
                    }
                    break;
                }

                case PartyListenerEventType.LEFT_PARTY:
                    goto IL_22D;

                case PartyListenerEventType.PRIVACY_CHANGED:
                    if (BnetParty.OnPrivacyLevelChanged != null)
                    {
                        BnetParty.OnPrivacyLevelChanged(BnetParty.GetJoinedParty(partyId), (PrivacyLevel)partyListenerEvent.UintData);
                    }
                    break;

                case PartyListenerEventType.MEMBER_JOINED:
                case PartyListenerEventType.MEMBER_LEFT:
                    if (BnetParty.OnMemberEvent != null)
                    {
                        OnlineEventType evt    = (partyListenerEvent.Type != PartyListenerEventType.MEMBER_JOINED) ? OnlineEventType.REMOVED : OnlineEventType.ADDED;
                        LeaveReason?    reason = null;
                        if (partyListenerEvent.Type == PartyListenerEventType.MEMBER_LEFT)
                        {
                            reason = new LeaveReason?((LeaveReason)partyListenerEvent.UintData);
                        }
                        BnetParty.OnMemberEvent(evt, BnetParty.GetJoinedParty(partyId), partyListenerEvent.SubjectMemberId, false, reason);
                    }
                    break;

                case PartyListenerEventType.MEMBER_ROLE_CHANGED:
                    if (BnetParty.OnMemberEvent != null)
                    {
                        BnetParty.OnMemberEvent(OnlineEventType.UPDATED, BnetParty.GetJoinedParty(partyId), partyListenerEvent.SubjectMemberId, true, null);
                    }
                    break;

                case PartyListenerEventType.RECEIVED_INVITE_ADDED:
                case PartyListenerEventType.RECEIVED_INVITE_REMOVED:
                    if (BnetParty.OnReceivedInvite != null)
                    {
                        OnlineEventType evt2 = (partyListenerEvent.Type != PartyListenerEventType.RECEIVED_INVITE_ADDED) ? OnlineEventType.REMOVED : OnlineEventType.ADDED;
                        PartyType       type = PartyType.DEFAULT;
                        if (partyListenerEvent.StringData != null)
                        {
                            EnumUtils.TryGetEnum <PartyType>(partyListenerEvent.StringData, out type);
                        }
                        PartyInfo          party   = new PartyInfo(partyId, type);
                        InviteRemoveReason?reason2 = null;
                        if (partyListenerEvent.Type == PartyListenerEventType.RECEIVED_INVITE_REMOVED)
                        {
                            reason2 = new InviteRemoveReason?((InviteRemoveReason)partyListenerEvent.UintData);
                        }
                        BnetParty.OnReceivedInvite(evt2, party, partyListenerEvent.UlongData, reason2);
                    }
                    break;

                case PartyListenerEventType.PARTY_INVITE_SENT:
                case PartyListenerEventType.PARTY_INVITE_REMOVED:
                    if (BnetParty.OnSentInvite != null)
                    {
                        bool            senderIsMyself = partyListenerEvent.SubjectMemberId == BnetGameAccountId.CreateFromEntityId(BattleNet.GetMyGameAccountId());
                        OnlineEventType evt3           = (partyListenerEvent.Type != PartyListenerEventType.PARTY_INVITE_SENT) ? OnlineEventType.REMOVED : OnlineEventType.ADDED;
                        PartyType       type2          = PartyType.DEFAULT;
                        if (partyListenerEvent.StringData != null)
                        {
                            EnumUtils.TryGetEnum <PartyType>(partyListenerEvent.StringData, out type2);
                        }
                        PartyInfo          party2  = new PartyInfo(partyId, type2);
                        InviteRemoveReason?reason3 = null;
                        if (partyListenerEvent.Type == PartyListenerEventType.PARTY_INVITE_REMOVED)
                        {
                            reason3 = new InviteRemoveReason?((InviteRemoveReason)partyListenerEvent.UintData);
                        }
                        BnetParty.OnSentInvite(evt3, party2, partyListenerEvent.UlongData, senderIsMyself, reason3);
                    }
                    break;

                case PartyListenerEventType.INVITE_REQUEST_ADDED:
                case PartyListenerEventType.INVITE_REQUEST_REMOVED:
                    if (BnetParty.OnSentInvite != null)
                    {
                        OnlineEventType            evt4        = (partyListenerEvent.Type != PartyListenerEventType.INVITE_REQUEST_ADDED) ? OnlineEventType.REMOVED : OnlineEventType.ADDED;
                        PartyInfo                  joinedParty = BnetParty.GetJoinedParty(partyId);
                        InviteRequestRemovedReason?reason4     = null;
                        if (partyListenerEvent.Type == PartyListenerEventType.INVITE_REQUEST_REMOVED)
                        {
                            reason4 = new InviteRequestRemovedReason?((InviteRequestRemovedReason)partyListenerEvent.UintData);
                        }
                        InviteRequest inviteRequest = new InviteRequest();
                        inviteRequest.TargetId      = partyListenerEvent.TargetMemberId;
                        inviteRequest.TargetName    = partyListenerEvent.StringData2;
                        inviteRequest.RequesterId   = partyListenerEvent.SubjectMemberId;
                        inviteRequest.RequesterName = partyListenerEvent.StringData;
                        BnetParty.OnReceivedInviteRequest(evt4, joinedParty, inviteRequest, reason4);
                    }
                    break;

                case PartyListenerEventType.CHAT_MESSAGE_RECEIVED:
                    if (BnetParty.OnChatMessage != null)
                    {
                        BnetParty.OnChatMessage(BnetParty.GetJoinedParty(partyId), partyListenerEvent.SubjectMemberId, partyListenerEvent.StringData);
                    }
                    break;

                case PartyListenerEventType.PARTY_ATTRIBUTE_CHANGED:
                {
                    PartyInfo joinedParty2 = BnetParty.GetJoinedParty(partyId);
                    string    stringData2  = partyListenerEvent.StringData;
                    if (stringData2 == "WTCG.Party.Type")
                    {
                        string    partyAttributeString = BnetParty.GetPartyAttributeString(partyId, "WTCG.Party.Type");
                        PartyType partyTypeFromString2 = BnetParty.GetPartyTypeFromString(partyAttributeString);
                        if (partyTypeFromString2 != PartyType.DEFAULT)
                        {
                            BnetParty.s_joinedParties[partyId] = partyTypeFromString2;
                        }
                    }
                    Variant variant = null;
                    switch (partyListenerEvent.UintData)
                    {
                    case 1u:
                        variant          = new Variant();
                        variant.IntValue = (long)partyListenerEvent.UlongData;
                        break;

                    case 2u:
                        variant             = new Variant();
                        variant.StringValue = partyListenerEvent.StringData2;
                        break;

                    case 3u:
                        variant           = new Variant();
                        variant.BlobValue = partyListenerEvent.BlobData;
                        break;
                    }
                    IL_611:
                    if (BnetParty.OnPartyAttributeChanged != null)
                    {
                        BnetParty.OnPartyAttributeChanged(joinedParty2, stringData2, variant);
                    }
                    List <BnetParty.PartyAttributeChangedHandler> list;
                    if (BnetParty.s_attributeChangedSubscribers != null && BnetParty.s_attributeChangedSubscribers.TryGetValue(stringData2, out list))
                    {
                        BnetParty.PartyAttributeChangedHandler[] array2 = list.ToArray();
                        foreach (BnetParty.PartyAttributeChangedHandler partyAttributeChangedHandler in array2)
                        {
                            partyAttributeChangedHandler(joinedParty2, stringData2, variant);
                        }
                    }
                    break;
                    goto IL_611;
                }
                }
IL_68C:
                i++;
                continue;
IL_22D:
                if (BnetParty.s_joinedParties.ContainsKey(partyId))
                {
                    PartyType type3 = BnetParty.s_joinedParties[partyId];
                    BnetParty.s_joinedParties.Remove(partyId);
                    if (BnetParty.OnJoined != null)
                    {
                        BnetParty.OnJoined(OnlineEventType.REMOVED, new PartyInfo(partyId, type3), new LeaveReason?((LeaveReason)partyListenerEvent.UintData));
                    }
                }
                goto IL_68C;
            }
        }
Пример #22
0
 public static void AcceptInviteRequest(PartyId partyId, BnetGameAccountId requestedTargetId)
 {
     BnetParty.SendInvite(partyId, requestedTargetId);
 }
Пример #23
0
 public static PartyInvite GetReceivedInvite(ulong inviteId)
 {
     PartyInvite[] receivedInvites = BnetParty.GetReceivedInvites();
     return(receivedInvites.FirstOrDefault((PartyInvite i) => i.InviteId == inviteId));
 }
Пример #24
0
 public static PartyInvite GetReceivedInviteFrom(BnetGameAccountId inviterId, PartyType partyType)
 {
     PartyInvite[] receivedInvites = BnetParty.GetReceivedInvites();
     return(receivedInvites.FirstOrDefault((PartyInvite i) => i.InviterId == inviterId && i.PartyType == partyType));
 }