Пример #1
0
        /// <summary>
        ///
        /// </summary>
        private void AddAccount(string account)
        {
            if (friendList.ContainsKey(account))
            {
                return;
            }

            friendList.Add(account, new List <CharacterObject>());

            IEnumerable <Session> sessions = NetworkManager.FindSession(account);

            foreach (Session session in sessions)
            {
                friendList[account].Add(session.Character);

                NetworkObject characterAdd = new NetworkObject();
                characterAdd.AddField(0, NetworkObjectField.CreateIntField((int)ServerFriendAction.Add));
                characterAdd.AddField(1, NetworkObjectField.CreateStringField(account));
                characterAdd.AddField(2, NetworkObjectField.CreateBoolField(true));
                characterAdd.AddField(3, NetworkObjectField.CreateObjectField(session.Character.ToNetworkObject()));
                owner.EnqueuePacket(new ServerObjectPacket(ObjectOpcode.FriendList, characterAdd, false));
            }

            if (friendList[account].Count == 0)
            {
                NetworkObject accountAdd = new NetworkObject();
                accountAdd.AddField(0, NetworkObjectField.CreateIntField((int)ServerFriendAction.Add));
                accountAdd.AddField(1, NetworkObjectField.CreateStringField(account));
                accountAdd.AddField(2, NetworkObjectField.CreateBoolField(false));
                owner.EnqueuePacket(new ServerObjectPacket(ObjectOpcode.FriendList, accountAdd, false));
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public override void AddMember(Session member)
        {
            NetworkObject fellowshipJoin = new NetworkObject();

            fellowshipJoin.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.Join));
            fellowshipJoin.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            member.EnqueueMessage(ObjectOpcode.Fellowship, fellowshipJoin);

            // send existing members to new member
            foreach (CharacterObject character in members)
            {
                NetworkObject fellowshipMemberJoin2 = new NetworkObject();
                fellowshipMemberJoin2.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.MemberJoin));
                fellowshipMemberJoin2.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
                fellowshipMemberJoin2.AddField(2, NetworkObjectField.CreateObjectField(character.ToNetworkObject()));
                member.EnqueueMessage(ObjectOpcode.Fellowship, fellowshipMemberJoin2);
            }

            base.AddMember(member);
            member.Fellowships.Add(this);

            // send new member to existing members
            NetworkObject fellowshipMemberJoin = new NetworkObject();

            fellowshipMemberJoin.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.MemberJoin));
            fellowshipMemberJoin.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            fellowshipMemberJoin.AddField(2, NetworkObjectField.CreateObjectField(member.Character.ToNetworkObject()));
            BroadcastMessage(ObjectOpcode.Fellowship, fellowshipMemberJoin);
        }
Пример #3
0
        /// <summary>
        /// Broadcast text message from <see cref="CharacterObject"/> to all members.
        /// </summary>
        public void BroadcastMessage(CharacterObject character, string message)
        {
            if (!HasMember(character))
            {
                return;
            }

            var channelMessage = new NetworkObject();

            channelMessage.AddField(0, NetworkObjectField.CreateIntField((int)ServerChannelAction.Message));
            channelMessage.AddField(1, NetworkObjectField.CreateObjectField(character.ToNetworkObject()));
            channelMessage.AddField(2, NetworkObjectField.CreateStringField(name));
            channelMessage.AddField(3, NetworkObjectField.CreateStringField(message));
            channelMessage.AddField(4, NetworkObjectField.CreateStringField(GetShortcut()));
            BroadcastMessage(ObjectOpcode.Channel, channelMessage);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        public void CharacterSignOut(string account, CharacterObject character)
        {
            if (!friendList.ContainsKey(account))
            {
                return;
            }

            friendList[account].Remove(character);

            NetworkObject characterSignOut = new NetworkObject();

            characterSignOut.AddField(0, NetworkObjectField.CreateIntField((int)ServerFriendAction.SignOut));
            characterSignOut.AddField(1, NetworkObjectField.CreateStringField(account));
            characterSignOut.AddField(2, NetworkObjectField.CreateObjectField(character.ToNetworkObject()));
            owner.EnqueuePacket(new ServerObjectPacket(ObjectOpcode.FriendList, characterSignOut, false));
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        public void CharacterSignIn(string account, CharacterObject character)
        {
            if (!friendList.ContainsKey(account))
            {
                return;
            }

            friendList[account].Add(character);

            NetworkObject characterSignIn = new NetworkObject();

            characterSignIn.AddField(0, NetworkObjectField.CreateIntField((int)ServerFriendAction.SignIn));
            characterSignIn.AddField(1, NetworkObjectField.CreateStringField(account));
            characterSignIn.AddField(2, NetworkObjectField.CreateObjectField(character.ToNetworkObject()));
            owner.EnqueueMessage(ObjectOpcode.FriendList, characterSignIn);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        public override void RemoveMember(Session member)
        {
            NetworkObject fellowshipMemberLeave = new NetworkObject();

            fellowshipMemberLeave.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.MemberLeave));
            fellowshipMemberLeave.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            fellowshipMemberLeave.AddField(2, NetworkObjectField.CreateUShortField((ushort)member.Character.Sequence));
            BroadcastMessage(ObjectOpcode.Fellowship, fellowshipMemberLeave);

            base.RemoveMember(member);
            member.Fellowships.Remove(this);

            NetworkObject fellowshipLeave = new NetworkObject();

            fellowshipLeave.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.Leave));
            fellowshipLeave.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            member.EnqueueMessage(ObjectOpcode.Fellowship, fellowshipLeave);
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        public void BroadcastMessage(Session member, string message)
        {
            if (!HasMember(member.Character))
            {
                return;
            }

            DatabaseManager.Database.LogConversation(name, member.Account.Username, message, member.Remote.Address.ToString());

            var channelMessage = new NetworkObject();

            channelMessage.AddField(0, NetworkObjectField.CreateIntField((int)ServerChannelAction.Message));
            channelMessage.AddField(1, NetworkObjectField.CreateObjectField(member.Character.ToNetworkObject()));
            channelMessage.AddField(2, NetworkObjectField.CreateStringField(name));
            channelMessage.AddField(3, NetworkObjectField.CreateStringField(message));
            channelMessage.AddField(4, NetworkObjectField.CreateStringField(GetShortcut()));
            BroadcastMessage(new ServerObjectPacket(ObjectOpcode.Channel, channelMessage, false));
        }
Пример #8
0
        public override byte[] Construct(PacketEncryptor encryptor)
        {
            var packet = new NetworkObject();

            packet.AddField(0, NetworkObjectField.CreateIntField((int)opcode));
            packet.AddField(1, NetworkObjectField.CreateObjectField(networkObject));

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write(0u);
                    writer.WritePackedUInt32((uint)flags);
                    writer.Write(NetworkObject.Pack(packet));

                    int length = (int)stream.Length - sizeof(int);
                    writer.Seek(0, SeekOrigin.Begin);
                    writer.Write(length);

                    return(stream.ToArray());
                }
            }
        }
Пример #9
0
        protected override void OnRemoveMember(CharacterObject character)
        {
            NetworkObject fellowshipMemberLeave = new NetworkObject();

            fellowshipMemberLeave.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.MemberLeave));
            fellowshipMemberLeave.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            fellowshipMemberLeave.AddField(2, NetworkObjectField.CreateUShortField((ushort)character.Sequence));
            BroadcastMessage(ObjectOpcode.Fellowship, fellowshipMemberLeave);

            members.Remove(character.Sequence);

            Session session = NetworkManager.FindSessionByCharacter(character);

            if (session != null)
            {
                session.Fellowships.Remove(this);

                NetworkObject fellowshipLeave = new NetworkObject();
                fellowshipLeave.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.Leave));
                fellowshipLeave.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
                session.EnqueueMessage(ObjectOpcode.Fellowship, fellowshipLeave);
            }
        }
Пример #10
0
        protected override void OnAddMember(CharacterObject character)
        {
            Session session = NetworkManager.FindSessionByCharacter(character);

            if (session == null)
            {
                return;
            }

            NetworkObject fellowshipJoin = new NetworkObject();

            fellowshipJoin.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.Join));
            fellowshipJoin.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            session.EnqueueMessage(ObjectOpcode.Fellowship, fellowshipJoin);

            // send existing members to new member
            foreach (CharacterObject existingCharacter in members.Values)
            {
                NetworkObject fellowshipMemberJoinExisting = new NetworkObject();
                fellowshipMemberJoinExisting.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.MemberJoin));
                fellowshipMemberJoinExisting.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
                fellowshipMemberJoinExisting.AddField(2, NetworkObjectField.CreateObjectField(existingCharacter.ToNetworkObject()));
                session.EnqueueMessage(ObjectOpcode.Fellowship, fellowshipMemberJoinExisting);
            }

            members.Add(character.Sequence, character);
            session.Fellowships.Add(this);

            // send new member to existing members
            NetworkObject fellowshipMemberJoin = new NetworkObject();

            fellowshipMemberJoin.AddField(0, NetworkObjectField.CreateIntField((int)FellowshipAction.MemberJoin));
            fellowshipMemberJoin.AddField(1, NetworkObjectField.CreateObjectField(Info.ToNetworkObject()));
            fellowshipMemberJoin.AddField(2, NetworkObjectField.CreateObjectField(character.ToNetworkObject()));
            BroadcastMessage(ObjectOpcode.Fellowship, fellowshipMemberJoin);
        }
Пример #11
0
        public static void HandleAuthenticate(Session session, NetworkObject networkObject)
        {
            void SendAuthenticationError(byte code)
            {
                var errorCode = new NetworkObject();

                errorCode.AddField(0, NetworkObjectField.CreateIntField(code));

                var authenticationError = new NetworkObject();

                authenticationError.AddField(0, NetworkObjectField.CreateIntField((int)ObjectOpcode.AuthenticateError));
                authenticationError.AddField(1, NetworkObjectField.CreateObjectField(errorCode));
                session.EnqueuePacket(new ServerAuthenticationPacket(authenticationError));
            }

            string username    = NetworkObjectField.ReadStringField(networkObject.GetField(2));
            string password    = NetworkObjectField.ReadStringField(networkObject.GetField(3));
            string version     = NetworkObjectField.ReadStringField(networkObject.GetField(5));
            string accountName = NetworkObjectField.ReadStringField(networkObject.GetField(6));

            CharacterObject characterObject = new CharacterObject();

            characterObject.FromNetworkObject(networkObject.GetField(4).ReadObject());

            if (string.IsNullOrWhiteSpace(username) ||
                username.Length > 20 ||
                username == "Anonymous")
            {
                SendAuthenticationError(0);
                return;
            }

            // anonymous login ignored
            if (version != "1.0.1.14")
            {
                SendAuthenticationError(1);
                return;
            }

            AccountInfo accountInfo = DatabaseManager.Database.GetAccount(username);

            if (accountInfo == null)
            {
                accountInfo = DatabaseManager.Database.CreateAccount(username, password, session.Remote.Address.ToString(), Privilege.All);
            }
            else
            {
                // validate existing account
                if (!BCryptProvider.Verify(password, accountInfo.Password))
                {
                    SendAuthenticationError(0);
                    return;
                }
            }

            log.Info($"Account: {accountInfo.Username}, Character: {characterObject.Name} has signed in!");

            DatabaseManager.Database.UpdateAccount(accountInfo.Id, session.Remote.Address.ToString());

            var authentication = new NetworkObject();

            authentication.AddField(0, NetworkObjectField.CreateIntField((int)ObjectOpcode.Authenticate));
            authentication.AddField(1, NetworkObjectField.CreateIntField((int)accountInfo.Privileges));
            session.EnqueuePacket(new ServerAuthenticationPacket(authentication));

            characterObject.Sequence = NetworkManager.SessionSequence.Dequeue();
            session.SignIn(accountInfo, accountName, characterObject);
        }