/// <summary> /// Adds a(n) <see cref="GroupMemberStructure"/> to the group. /// </summary> public bool AddMember(GroupMemberStructure memberToAddInfo) { if (members.Count >= GlobalGameSettings.MAX_GROUP_MEMBERS) { return(false); } this.members.Add(memberToAddInfo); return(true); }
/// <summary> /// Forms a new group /// </summary> public void FormNewGroup(IGroupMember groupLeader) { // we are using the current zone id as the sub id so group ids created in different zones will not collide with each other this.guid = new MmoGuid((byte)ObjectType.Group, GroupManager.Instance.GenerateGroupId()); this.leader = new GroupMemberStructure(groupLeader.Guid, groupLeader.Name); // add the leader as our first member this.AddMember(groupLeader); // add the group to the group manager GroupManager.Instance.AddGroup(this); }
/// <summary> /// Forms an existing group /// </summary> public bool FormExistingGroup(MmoGuid groupGuid, GroupMemberStructure groupLeader) { this.guid = groupGuid; this.leader = groupLeader; // making sure that we do not already have a group with the same id // if its already been added and its us then we dont have to do anything // otherwise throw error Group oldGroup; if (GroupManager.Instance.TryGetGroup(guid, out oldGroup)) { if (oldGroup != this) { throw new ArgumentException("ExistingGroupWithSameId"); } return(true); } GroupManager.Instance.AddGroup(this); return(true); }
public bool Equals(GroupMemberStructure groupMemberInfo) { return(groupMemberInfo.Guid == this.Guid); }
/// <summary> /// Adds a(n) <see cref="IGroupMember"/> to the group. /// </summary> public bool AddMember(IGroupMember memberToAdd) { if (memberToAdd.InGroup()) { return(false); } if (members.Count >= GlobalGameSettings.MAX_GROUP_MEMBERS) { return(false); } var memberToAddInfo = new GroupMemberStructure(memberToAdd.Guid, memberToAdd.Name); this.members.Add(memberToAddInfo); // this will set the member's current group to this memberToAdd.Group = this; // only send updates if there are more than one player in the group // a group of one means its just the leader waiting for the other player to accept the invite if (members.Count > 1) { // sending the player the group info so it can setup the group var groupInit = new GroupInit { GroupData = new GroupStructure(guid, leader.Guid) }; memberToAdd.Peer.SendEvent(groupInit, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); // if the group chat channel has not been registered yet, register it // doing it this way will only create the channel if there are more than one players in the group if (!IsFormed) { // creating the group in every worlds foreach (var world in social.Worlds) { world.GroupManager.FormGroup(guid, leader); } // TODO: Send it via an event channel // send any remaining players the init message (usually the leader) foreach (var memberReference in memberReferences.Values) { memberReference.Object.Peer.SendEvent(groupInit, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); } // create our chat channel this.CreateChatChannel(); // mark the group formed this.IsFormed = true; } // TODO: Send it via an event channel // adding the member in every world groups if (IsFormed) { foreach (var world in social.Worlds) { world.GroupManager.AddMember(guid, memberToAddInfo); } } foreach (var profile in members) { // skip us if (profile.Guid == memberToAdd.Guid) { continue; } Reference <IGroupMember> reference; if (memberReferences.TryGetValue(profile.Guid, out reference)) { var activeMember = reference.Object; activeMember.Peer.SendEvent( new GroupMemberAdded { GroupMemberData = new GroupMemberStructure(memberToAdd.Guid.Id, memberToAdd.Name) }, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); memberToAdd.Peer.SendEvent( new GroupMemberAdded { GroupMemberData = new GroupMemberStructure(activeMember.Guid.Id, activeMember.Name) }, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); } else { memberToAdd.Peer.SendEvent( new GroupMemberAddedInactive { GroupMemberData = new GroupMemberStructure(profile.Guid.Id, profile.Name) }, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); } } // if the chat channel is available join the new user to it if (channelId > 0) { this.social.ChatManager.JoinChannel(memberToAdd.SessionId, this.channelId); } } // adding the member reference to send updates this.DoAddReference(memberToAdd); return(true); }
/// <summary> /// Adds a(n) <see cref="IGroupMember"/> to the group. /// </summary> public bool AddMember(IGroupMember memberToAdd) { if (memberToAdd.InGroup()) { return(false); } if (members.Count >= GlobalGameSettings.MAX_GROUP_MEMBERS) { return(false); } var memberInfo = new GroupMemberStructure(memberToAdd.Guid, memberToAdd.Name); this.members.Add(memberInfo); // this will set the member's current group to this memberToAdd.Group = this; // only send updates if there are more than one player in the group // seriously what is there to send if its only one player // a group of one means its just the leader waiting for the other player to accept the invite if (memberReferences.Count > 0) { foreach (var memberReference in memberReferences.Values) { // skip us var member = memberReference.Object; var memberGuid = member.Guid; var memberToAddGuid = memberToAdd.Guid; if (memberGuid == memberToAddGuid) { continue; } if (!member.IsVisible(memberToAddGuid)) { // otherwise we need to manually build the updates memberToAdd.MemberUpdateFlags = GroupMemberPropertyFlags.PROPERTY_FLAG_ALL; var properties = memberToAdd.BuildGroupMemberProperties(); memberToAdd.MemberUpdateFlags = GroupMemberPropertyFlags.PROPERTY_FLAG_NONE; // send the updates only if there is properties to send if (properties != null) { var groupMemberUpdate = new GroupMemberUpdate { ObjectId = memberToAddGuid, Properties = properties }; member.Peer.SendEvent(groupMemberUpdate, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); } } if (!memberToAdd.IsVisible(memberGuid)) { // otherwise we need to manually build the updates member.MemberUpdateFlags = GroupMemberPropertyFlags.PROPERTY_FLAG_ALL; var properties = member.BuildGroupMemberProperties(); member.MemberUpdateFlags = GroupMemberPropertyFlags.PROPERTY_FLAG_NONE; // send the updates only if there is properties to send if (properties != null) { var groupMemberUpdate = new GroupMemberUpdate { ObjectId = memberGuid, Properties = properties }; memberToAdd.Peer.SendEvent(groupMemberUpdate, new MessageParameters { ChannelId = PeerSettings.GroupEventChannel }); } } } } // adding the member reference to send updates this.AddReference(memberToAdd); return(true); }