Esempio n. 1
0
        void c_ClientChannelChangeInfo(object sender, ClientChannelChangeEventArgs e)
        {
            Client            c   = (Client)sender;
            ChannelChangeInfo cci = e.Info;

            Client[] nearbyClients = GetNearByClients(c, false);

            switch (cci.Something2)
            {
            case 1:
                byte[] bufferSendChannelChange = PacketManager.SendChannelChange(cci.Something, cci.Something2);
                c.Send(bufferSendChannelChange);

                byte[] bufferRemoveCharacter = PacketManager.SendRemoveCharacter(c.MyCharacter);
                SendSpecific(nearbyClients, bufferRemoveCharacter);
                break;

            case 0:
                accountManager.ExitGame(c.AccountID);

                bufferRemoveCharacter = PacketManager.SendRemoveCharacter(c.MyCharacter);
                SendSpecific(nearbyClients, bufferRemoveCharacter);
                break;
            }
        }
Esempio n. 2
0
        private void HandleRecvChannelChange(Packet parsed)
        {
            ChannelChangeInfo cci = PacketManager.RecvChannelChange(parsed);

            if (ClientChannelChangeInfo != null)
            {
                ClientChannelChangeInfo(this, new ClientChannelChangeEventArgs(cci));
            }
        }
Esempio n. 3
0
        public ReceivedChannelChannelResultEventArgs(ChannelChangeInfo moveInfo, ChannelChangeResult result)
        {
            if (moveInfo == null)
            {
                throw new ArgumentNullException("moveInfo");
            }

            this.MoveInfo = moveInfo;
            this.Result   = result;
        }
Esempio n. 4
0
        public void Move(IUserInfo user, IChannelInfo channel)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            int previousChannel = user.CurrentChannelId;

            if (previousChannel == channel.ChannelId)
            {
                return;
            }

            IUserInfo realUser = this[user.UserId];

            if (realUser == null)
            {
                return;
            }

            IChannelInfo realChannel = context.Channels[channel.ChannelId];

            if (realChannel == null)
            {
                return;
            }

            var changeInfo = new ChannelChangeInfo(user.UserId, channel.ChannelId, previousChannel);

            int numUsers = context.Users.Count(u => u.CurrentChannelId == channel.ChannelId);

            if (channel.UserLimit != 0 && numUsers >= channel.UserLimit)
            {
                return;
            }

            Manager.Move(realUser, realChannel);

            foreach (var connection in Manager.GetConnections())
            {
                connection.SendAsync(new UserChangedChannelMessage {
                    ChangeInfo = changeInfo
                });
            }
        }
Esempio n. 5
0
        public void UserChangedChannel()
        {
            var changeInfo = new ChannelChangeInfo(1, 2, 3);
            var msg        = new UserChangedChannelMessage {
                ChangeInfo = changeInfo
            };

            Assert.AreEqual(changeInfo.TargetUserId, msg.ChangeInfo.TargetUserId);
            Assert.AreEqual(changeInfo.TargetChannelId, msg.ChangeInfo.TargetChannelId);
            Assert.AreEqual(changeInfo.RequestingUserId, msg.ChangeInfo.RequestingUserId);
            msg.WritePayload(serverContext, writer);
            long length = stream.Position;

            stream.Position = 0;

            msg = new UserChangedChannelMessage();
            msg.ReadPayload(clientContext, reader);
            Assert.AreEqual(length, stream.Position);
            Assert.AreEqual(changeInfo.TargetUserId, msg.ChangeInfo.TargetUserId);
            Assert.AreEqual(changeInfo.TargetChannelId, msg.ChangeInfo.TargetChannelId);
            Assert.AreEqual(changeInfo.RequestingUserId, msg.ChangeInfo.RequestingUserId);
        }
Esempio n. 6
0
 public ClientChannelChangeEventArgs(ChannelChangeInfo cci)
 {
     this.channelInfo = cci;
 }
Esempio n. 7
0
        private void MoveUser(int moverId, int userId, int channelId)
        {
            IConnection requester      = null;
            IUserInfo   requestingUser = (moverId == 0) ? null : this.context.Users[moverId];

            if (requestingUser != null)
            {
                requester = this.context.Users[requestingUser];
            }

            IUserInfo user = this.context.Users[userId];

            if (user == null)
            {
                return;
            }

            ChannelChangeInfo info = (requestingUser != null)
                                                        ? new ChannelChangeInfo(userId, channelId, user.CurrentChannelId, requestingUser.UserId)
                                                        : new ChannelChangeInfo(userId, channelId, user.CurrentChannelId);

            IChannelInfo channel = this.context.Channels[channelId];

            if (channel == null)
            {
                if (requester != null)
                {
                    requester.SendAsync(new ChannelChangeResultMessage(ChannelChangeResult.FailedUnknownChannel, info));
                }

                return;
            }

            if (!user.Equals(requestingUser))
            {
                if (!this.context.GetPermission(PermissionName.ChangePlayersChannel, channel.ChannelId, moverId))
                {
                    if (requester != null)
                    {
                        requester.SendAsync(new ChannelChangeResultMessage(ChannelChangeResult.FailedPermissions, info));
                    }

                    return;
                }
            }
            else if (!this.context.GetPermission(PermissionName.ChangeChannel, channel.ChannelId, user.UserId))
            {
                if (requester != null)
                {
                    requester.SendAsync(new ChannelChangeResultMessage(ChannelChangeResult.FailedPermissions, info));
                }

                return;
            }

            if (channel.UserLimit != 0 && channel.UserLimit <= context.Users.Count(u => u.CurrentChannelId == channel.ChannelId))
            {
                if (requester != null)
                {
                    requester.SendAsync(new ChannelChangeResultMessage(ChannelChangeResult.FailedFull, info));
                }

                return;
            }

            Manager.Move(user, channel);

            foreach (IConnection connection in Manager.GetConnections())
            {
                connection.SendAsync(new UserChangedChannelMessage {
                    ChangeInfo = info
                });
            }
        }