Exemple #1
0
        public void deletePendingClient(NetComputer client)
        {
            MessageOut msg=new MessageOut(Protocol.CPMSG_CONNECT_RESPONSE);
            msg.writeInt8((int)ErrorMessage.ERRMSG_TIME_OUT);

            // The computer will be deleted when the disconnect event is processed
            client.disconnect(msg);
        }
Exemple #2
0
        void tokenMatched(ChatClient client, Pending p)
        {
            MessageOut msg=new MessageOut(Protocol.CPMSG_CONNECT_RESPONSE);

            client.characterName = p.character;
            client.accountLevel = p.level;

            Character c = Program.storage.getCharacter(p.character);

            if (c!=null)
            {
                // character wasnt found
                msg.writeInt8((int)ErrorMessage.ERRMSG_FAILURE); //TODO In Protocol?
            }
            else
            {
                client.characterId = (uint)c.getDatabaseID();
                //delete p;

                msg.writeInt8((int)ErrorMessage.ERRMSG_OK);

                // Add chat client to player map
                mPlayerMap.Add(client.characterName, client);
            }

            client.send(msg);
        }
Exemple #3
0
        void handleRegisterMessage(AccountClient client, MessageIn msg)
        {
            int clientVersion=msg.readInt32();
            string username=msg.readString();
            string password=msg.readString();
            string email=msg.readString();
            string captcha=msg.readString();

            MessageOut reply=new MessageOut(Protocol.APMSG_REGISTER_RESPONSE);

            if(client.status!=AccountClientStatus.CLIENT_LOGIN)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }
            else if(!mRegistrationAllowed)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }
            else if(clientVersion<ManaServ.PROTOCOL_VERSION)
            {
                reply.writeInt8((int)Register.REGISTER_INVALID_VERSION);
            }
            else if(Program.stringFilter.findDoubleQuotes(username)
                ||Program.stringFilter.findDoubleQuotes(email)
                ||username.Length<mMinNameLength
                ||username.Length>mMaxNameLength
                ||!Program.stringFilter.isEmailValid(email)
                ||!Program.stringFilter.filterContent(username))
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else if(Program.storage.doesUserNameExist(username))
            {
                reply.writeInt8((int)Register.REGISTER_EXISTS_USERNAME);
            }
            else if(Program.storage.doesEmailAddressExist(SHA256.HashString(email)))
            {
                reply.writeInt8((int)Register.REGISTER_EXISTS_EMAIL);
            }
            else if(!checkCaptcha(client, captcha))
            {
                reply.writeInt8((int)Register.REGISTER_CAPTCHA_WRONG);
            }
            else
            {
                ISL.Server.Account.Account acc=new ISL.Server.Account.Account();
                acc.setName(username);
                acc.setPassword(SHA256.HashString(password));

                // We hash email server-side for additional privacy
                // we ask for it again when we need it and verify it
                // through comparing it with the hash.
                acc.setEmail(SHA256.HashString(email));
                acc.setLevel((int)AccessLevel.AL_PLAYER);

                // Set the date and time of the account registration, and the last login
                DateTime regdate=DateTime.Now;
                acc.setRegistrationDate(regdate);
                acc.setLastLogin(regdate);

                Program.storage.addAccount(acc);
                reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                addServerInfo(reply);

                // Associate account with connection
                client.setAccount(acc);
                client.status=AccountClientStatus.CLIENT_CONNECTED;
            }

            client.send(reply);
        }
Exemple #4
0
        void handleCharacterSelectMessage(AccountClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.APMSG_CHAR_SELECT_RESPONSE);

            ISL.Server.Account.Account acc=client.getAccount();

            if(acc==null)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_NO_LOGIN);
                client.send(reply);
                return; // not logged in
            }

            int slot=msg.readInt8();
            Dictionary<uint, Character> chars=acc.getCharacters();

            if(chars.ContainsKey((uint)slot)==false)
            {
                // Invalid char selection
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
                client.send(reply);
                return;
            }

            Character selectedChar=chars[(uint)slot];

            string address;
            int port;

            int charMapId=selectedChar.getMapId();
            bool gameServerHasMap=GameServerHandler.getGameServerFromMap(charMapId, out address, out port);

            if(!gameServerHasMap)
            {
                Logger.Write(LogLevel.Error, "Character Selection: No game server for map #{0}", selectedChar.getMapId());
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                client.send(reply);
                return;
            }

            reply.writeInt8((int)ErrorMessage.ERRMSG_OK);

            Logger.Write(LogLevel.Debug, "{0} is trying to enter the servers.", selectedChar.getName());

            string magic_token=Various.GetUniqueID();
            reply.writeString(magic_token);
            reply.writeString(address);
            reply.writeInt16(port);

            // Give address and port for the chat server
            reply.writeString(Configuration.getValue("net_chatHost", "localhost"));

            // When the chatListenToClientPort is set, we use it.
            // Otherwise, we use the accountListenToClientPort + 2 if the option is set.
            // If neither, the DEFAULT_SERVER_PORT + 2 is used.
            int alternativePort=Configuration.getValue("net_accountListenToClientPort", Configuration.DEFAULT_SERVER_PORT)+2;
            reply.writeInt16(Configuration.getValue("net_chatListenToClientPort", alternativePort));

            GameServerHandler.registerClient(magic_token, selectedChar); //TODO Überprüfen ob diese beiden Funktionen funktionieren
            ChatHandler.registerChatClient(magic_token, selectedChar.getName(), acc.getLevel());

            client.send(reply);

            // log transaction
            Transaction trans=new Transaction();
            trans.mCharacterId=(uint)selectedChar.getDatabaseID();
            trans.mAction=(uint)TransactionMembers.TRANS_CHAR_SELECTED;

            Program.storage.addTransaction(trans);
        }
Exemple #5
0
 void deletePendingClient(AccountClient client)
 {
     MessageOut msg=new MessageOut(Protocol.APMSG_RECONNECT_RESPONSE);
     msg.writeInt8((int)ErrorMessage.ERRMSG_TIME_OUT);
     client.disconnect(msg);
     // The client will be deleted when the disconnect event is processed
 }
Exemple #6
0
        public void tokenMatched(NetComputer computer, object data)
        {
            int accountID=(int)data;
            AccountClient client=(AccountClient)computer;

            MessageOut reply=new MessageOut(Protocol.APMSG_RECONNECT_RESPONSE);

            // Associate account with connection.
            ISL.Server.Account.Account acc=Program.storage.getAccount(accountID);
            client.setAccount(acc);
            client.status=AccountClientStatus.CLIENT_CONNECTED;

            reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
            client.send(reply);

            // Return information about available characters
            Dictionary<uint, Character> chars=acc.getCharacters();

            // Send characters list
            foreach(KeyValuePair<uint, Character> pair in chars)
            {
                sendCharacterData(client, pair.Value);
            }
        }
Exemple #7
0
        void sendCharacterData(AccountClient client, Character ch)
        {
            MessageOut charInfo=new MessageOut(Protocol.APMSG_CHAR_INFO);

            charInfo.writeInt8((int)ch.getCharacterSlot());
            charInfo.writeString(ch.getName());
            charInfo.writeInt8(ch.getGender());
            charInfo.writeInt8(ch.getHairStyle());
            charInfo.writeInt8(ch.getHairColor());
            charInfo.writeInt16(ch.getLevel());
            charInfo.writeInt16(ch.getCharacterPoints());
            charInfo.writeInt16(ch.getCorrectionPoints());

            foreach(KeyValuePair<uint, AttributeValue> at in ch.mAttributes)
            {
                charInfo.writeInt32((int)at.Key);
                charInfo.writeInt32((int)(at.Value.@base*256));
                charInfo.writeInt32((int)(at.Value.modified*256));
            }

            client.send(charInfo);
        }
Exemple #8
0
        void handlePartyQuit(ChatClient client)
        {
            removeUserFromParty(client);
            MessageOut outmsg=new MessageOut(Protocol.CPMSG_PARTY_QUIT_RESPONSE);
            outmsg.writeInt8((int)ErrorMessage.ERRMSG_OK);
            client.send(outmsg);

            // tell game server to update info
            updateInfo(client, 0);
        }
Exemple #9
0
        void handleEnterChannelMessage(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_ENTER_CHANNEL_RESPONSE);

            string channelName=msg.readString();
            string givenPassword=msg.readString();
            ChatChannel channel=null;

            if(Program.chatChannelManager.channelExists(channelName)||
                Program.chatChannelManager.tryNewPublicChannel(channelName))
            {
                channel=Program.chatChannelManager.getChannel(channelName);
            }

            if(channel!=null)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else if(channel.getPassword()!=null&&channel.getPassword()!=givenPassword)
            {
                // Incorrect password (should probably have its own return value)
                reply.writeInt8((int)ErrorMessage.ERRMSG_INSUFFICIENT_RIGHTS);
            }
            else if(!channel.canJoin())
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else
            {
                if(channel.addUser(client))
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                    // The user entered the channel, now give him the channel
                    // id, the announcement string and the user list.
                    reply.writeInt16(channel.getId());
                    reply.writeString(channelName);
                    reply.writeString(channel.getAnnouncement());
                    List<ChatClient> users=channel.getUserList();

                    foreach(ChatClient user in users)
                    {
                        reply.writeString(user.characterName);
                        reply.writeString(channel.getUserMode(user));
                    }

                    // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went
                    // in the channel.
                    warnUsersAboutPlayerEventInChat(channel, client.characterName, (int)ChatValues.CHAT_EVENT_NEW_PLAYER);

                    // log transaction
                    Transaction trans=new Transaction();
                    trans.mCharacterId=client.characterId;
                    trans.mAction=(uint)TransactionMembers.TRANS_CHANNEL_JOIN;
                    trans.mMessage="User joined "+channelName;
                    Program.storage.addTransaction(trans);
                }
                else
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                }
            }

            client.send(reply);
        }
Exemple #10
0
 void handleDisconnectMessage(ChatClient client, MessageIn msg)
 {
     MessageOut reply=new MessageOut(Protocol.CPMSG_DISCONNECT_RESPONSE);
     reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
     Program.chatChannelManager.removeUserFromAllChannels(client);
     Program.guildManager.disconnectPlayer(client);
     client.send(reply);
 }
Exemple #11
0
 void handleCommand(ChatClient computer, string command)
 {
     Logger.Write(LogLevel.Information, "Chat: Received unhandled command:  {0}", command);
     MessageOut result=new MessageOut(Protocol.CPMSG_ERROR);
     result.writeInt8((int)ChatValues.CHAT_UNHANDLED_COMMAND); //TODO sollte im Protocol landen
     computer.send(result);
 }
Exemple #12
0
        void handleAnnounceMessage(ChatClient client, MessageIn msg)
        {
            string text=msg.readString();

            if(!Program.stringFilter.filterContent(text))
            {
                warnPlayerAboutBadWords(client);
                return;
            }

            if(client.accountLevel==(byte)AccessLevel.AL_ADMIN||client.accountLevel==(byte)AccessLevel.AL_GM)
            {
                // TODO: b_lindeijer: Shouldn't announcements also have a sender?
                Logger.Write(LogLevel.Information, "ANNOUNCE: {0}", text);
                MessageOut result=new MessageOut(Protocol.CPMSG_ANNOUNCEMENT);
                result.writeString(text);

                // We send the message to all players in the default channel as it is
                // an announcement.
                sendToEveryone(result);

                // log transaction
                Transaction trans=new Transaction();
                trans.mCharacterId=client.characterId;
                trans.mAction=(uint)TransactionMembers.TRANS_MSG_ANNOUNCE;
                trans.mMessage="User announced "+text;
                Program.storage.addTransaction(trans);
            }
            else
            {
                MessageOut result=new MessageOut(Protocol.CPMSG_ERROR);
                result.writeInt8((int)ErrorMessage.ERRMSG_INSUFFICIENT_RIGHTS);
                client.send(result);
                Logger.Write(LogLevel.Information, "{0} couldn't make an announcement due to insufficient rights.", client.characterName);
            }
        }
Exemple #13
0
 public void warnUsersAboutPlayerEventInChat(ChatChannel channel, string info, byte eventId)
 {
     MessageOut msg=new MessageOut(Protocol.CPMSG_CHANNEL_EVENT);
     msg.writeInt16(channel.getId());
     msg.writeInt8(eventId);
     msg.writeString(info);
     sendInChannel(channel, msg);
 }
Exemple #14
0
        public void sendGuildListUpdate(string guildName, string characterName, byte eventId)
        {
            Guild guild=Program.guildManager.findByName(guildName);

            if(guild!=null)
            {
                MessageOut msg=new MessageOut(Protocol.CPMSG_GUILD_UPDATE_LIST);

                msg.writeInt16(guild.getId());
                msg.writeString(characterName);
                msg.writeInt8(eventId);

                foreach(GuildMember member in guild.getMembers())
                {
                    Character c=Program.storage.getCharacter(member.mId, null);

                    if(mPlayerMap.ContainsKey(c.getName()))
                    {
                        ChatClient chr=mPlayerMap[c.getName()];
                        chr.send(msg);
                    }
                }
            }
        }
Exemple #15
0
        void warnPlayerAboutBadWords(ChatClient computer)
        {
            // We could later count if the player is really often unpolite.
            MessageOut result=new MessageOut(Protocol.CPMSG_ERROR);
            result.writeInt8((int)ChatValues.CHAT_USING_BAD_WORDS); // The Channel //TODO sollte im Protocol landen
            computer.send(result);

            Logger.Write(LogLevel.Information, "{0} says bad words.", computer.characterName);
        }
Exemple #16
0
        public void handlePartyInvite(MessageIn msg)
        {
            string inviterName = msg.readString();
            string inviteeName = msg.readString();
            ChatClient inviter = getClient(inviterName);
            ChatClient invitee = getClient(inviteeName);

            if (inviter==null|| invitee==null) return;

            removeExpiredPartyInvites();
            int maxInvitesPerTimeframe = 10;

            int num = mNumInvites[inviterName];

            if (num >= maxInvitesPerTimeframe)
            {
                MessageOut @out=new MessageOut(Protocol.CPMSG_PARTY_REJECTED);
                @out.writeString(inviterName);
                @out.writeInt8((int)ErrorMessage.ERRMSG_LIMIT_REACHED);
                inviter.send(@out);
                return;
            }
            ++num;

            if (invitee.party!=null)
            {
                MessageOut @out=new MessageOut(Protocol.CPMSG_PARTY_REJECTED);
                @out.writeString(inviterName);
                @out.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                inviter.send(@out);
                return;
            }

            mInvitations.Add(new PartyInvite(inviterName, inviteeName));

            MessageOut msgout=new MessageOut(Protocol.CPMSG_PARTY_INVITED);
            msgout.writeString(inviterName);
            invitee.send(msgout);
        }
Exemple #17
0
        void handlePartyInviteAnswer(ChatClient client, MessageIn msg)
        {
            if(client.party==null) return;

            MessageOut outInvitee=new MessageOut(Protocol.CPMSG_PARTY_INVITE_ANSWER_RESPONSE);

            string inviter=msg.readString();

            // check if the invite is still valid
            bool valid=false;
            removeExpiredPartyInvites();
            int size=mInvitations.Count;

            for(int i=0; i<size; i++)
            {
                if(mInvitations[i].mInviter==inviter&&mInvitations[i].mInvitee==client.characterName)
                {
                    valid=true;
                }
            }

            // the invitee did not accept the invitation
            //if (msg.readInt8();)
            //{
            msg.readInt8();

            if(!valid) return;

            // send rejection to inviter
            ChatClient inviterClient=getClient(inviter);

            if(inviterClient!=null)
            {
                MessageOut outmsg=new MessageOut(Protocol.CPMSG_PARTY_REJECTED);
                outmsg.writeString(inviter);
                outmsg.writeInt8((int)ErrorMessage.ERRMSG_OK);
                inviterClient.send(outmsg);
            }
            return;
            //}

            // if the invitation has expired, tell the inivtee about it
            if(!valid)
            {
                outInvitee.writeInt8((int)ErrorMessage.ERRMSG_TIME_OUT);
                client.send(outInvitee);
                return;
            }

            // check that the inviter is still in the game
            ChatClient c1=getClient(inviter);
            if(c1==null)
            {
                outInvitee.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                client.send(outInvitee);
                return;
            }

            // if party doesnt exist, create it
            if(c1.party!=null)
            {
                c1.party=new Party();
                //c1.party.addUser(inviter);
                c1.party.addUser("", inviter); //TODO Überprüfen
                // tell game server to update info
                updateInfo(c1, (int)c1.party.getId());
            }

            outInvitee.writeInt8((int)ErrorMessage.ERRMSG_OK);

            List<string> users=c1.party.getUsers();

            int usersSize=users.Count;

            for(int i=0; i<usersSize; i++)
            {
                outInvitee.writeString(users[i]);
            }

            client.send(outInvitee);

            // add invitee to the party
            c1.party.addUser(client.characterName, inviter);
            client.party=c1.party;

            // tell game server to update info
            updateInfo(client, (int)client.party.getId());
        }
Exemple #18
0
        void handleGuildAcceptInvite(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_ACCEPT_RESPONSE);
            string guildName = msg.readString();
            bool error = true; // set true by default, and set false only if success

            // check guild exists and that member was invited
            // then add them as guild member
            // and remove from invite list
            Guild guild = Program.guildManager.findByName(guildName);

            if (guild!=null)
            {
                if (guild.checkInvited((int)client.characterId))
                {
                    // add user to guild
                    Program.guildManager.addGuildMember(guild, (int)client.characterId);
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                    reply.writeString(guild.getName());
                    reply.writeInt16(guild.getId());
                    reply.writeInt16(guild.getUserPermissions((int)client.characterId));

                    // have character join guild channel
                    ChatChannel channel = joinGuildChannel(guild.getName(), client);
                    reply.writeInt16(channel.getId());
                    sendGuildListUpdate(guildName, client.characterName, (int)GuildValues.GUILD_EVENT_NEW_PLAYER);

                    // success! set error to false
                    error = false;
                }
            }

            if (error)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }

            client.send(reply);
        }
Exemple #19
0
        void handleQuitChannelMessage(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_QUIT_CHANNEL_RESPONSE);

            short channelId = msg.readInt16();
            ChatChannel channel = Program.chatChannelManager.getChannel(channelId);

            if (channelId == 0 || channel!=null)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else if (!channel.removeUser(client))
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }
            else
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                reply.writeInt16(channelId);

                // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user left
                // the channel.
                warnUsersAboutPlayerEventInChat(channel, client.characterName, (int)ChatValues.CHAT_EVENT_LEAVING_PLAYER);

                // log transaction
                Transaction trans=new Transaction();
                trans.mCharacterId = client.characterId;
                trans.mAction =(uint)TransactionMembers.TRANS_CHANNEL_QUIT;
                trans.mMessage = "User left " + channel.getName();
                Program.storage.addTransaction(trans);

                if (channel.getUserList()!=null)
                {
                    Program.chatChannelManager.removeChannel(channel.getId());
                }
            }

            client.send(reply);
        }
Exemple #20
0
        void handleGuildCreate(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_CREATE_RESPONSE);

            // Check if guild already exists and if so, return error
            string guildName = msg.readString();

            if (!Program.guildManager.doesExist(guildName))
            {
                // check the player hasnt already created a guild
                if(Program.guildManager.alreadyOwner((int)client.characterId))
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_LIMIT_REACHED);
                }
                else
                {
                    // Guild doesnt already exist so create it
                    Guild guild=Program.guildManager.createGuild(guildName, (int)client.characterId);
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                    reply.writeString(guildName);
                    reply.writeInt16(guild.getId());
                    reply.writeInt16(guild.getUserPermissions((int)client.characterId));

                    // Send autocreated channel id
                    ChatChannel channel = joinGuildChannel(guildName, client);
                    reply.writeInt16(channel.getId());
                }
            }
            else
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_ALREADY_TAKEN);
            }

            client.send(reply);
        }
Exemple #21
0
        void tokenMatched(AccountClient client, int accountID)
        {
            MessageOut reply=new MessageOut(Protocol.APMSG_RECONNECT_RESPONSE);

            //Associate account with connection.
            ISL.Server.Account.Account acc=Program.storage.getAccount(accountID);
            client.setAccount(acc);
            client.status=AccountClientStatus.CLIENT_CONNECTED;

            reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
            client.send(reply);

            // Return information about available characters
            Dictionary<uint, Character> chars=acc.getCharacters();

            // Send characters list
            foreach(Character character in chars.Values)
            {
                sendCharacterData(client, character);
            }
        }
Exemple #22
0
        void handleGuildGetMembers(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_GET_MEMBERS_RESPONSE);
            short guildId = msg.readInt16();
            Guild guild = Program.guildManager.findById(guildId);

            // check for valid guild
            // write a list of member names that belong to the guild
            if (guild!=null)
            {
                // make sure the requestor is in the guild
                if (guild.checkInGuild((int)client.characterId))
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                    reply.writeInt16(guildId);

                    foreach(GuildMember member in guild.getMembers())
                    {
                        Character c = Program.storage.getCharacter(member.mId, null);
                        string memberName = c.getName();
                        reply.writeString(memberName);
                        reply.writeInt8((int)((mPlayerMap.ContainsKey(memberName)?1:0)));
                    }
                }
            }
            else
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }

            client.send(reply);
        }
Exemple #23
0
 /**
  * Adds server specific info to the current message
  *
  * The info are made of:
  * (String) Update Host URL (or "")
  * (String) Client Data URL (or "")
  * (Byte)   Number of maximum character slots (empty or not)
  */
 void addServerInfo(MessageOut msg)
 {
     msg.writeString(mUpdateHost);
     /*
      * This is for developing/testing an experimental new resource manager that
      * downloads only the files it needs on demand.
      */
     msg.writeString(mDataUrl);
     msg.writeInt8(mMaxCharacters);
 }
Exemple #24
0
        void handleGuildInvite(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_INVITE_RESPONSE);
            MessageOut invite=new MessageOut(Protocol.CPMSG_GUILD_INVITED);

            // send an invitation from sender to character to join guild
            int guildId=msg.readInt16();
            string character=msg.readString();

            // get the chat client and the guild
            ChatClient invitedClient=mPlayerMap[character];
            Guild guild=Program.guildManager.findById((short)guildId);

            if(invitedClient!=null&&guild!=null)
            {
                // check permissions of inviter, and that they arent inviting themself,
                // and arent someone already in the guild
                if(guild.canInvite((int)client.characterId)&&(client.characterName!=character)&&!guild.checkInGuild((int)invitedClient.characterId))
                {
                    // send the name of the inviter and the name of the guild
                    // that the character has been invited to join
                    string senderName=client.characterName;
                    string guildName=guild.getName();
                    invite.writeString(senderName);
                    invite.writeString(guildName);
                    invite.writeInt16(guildId);
                    invitedClient.send(invite);
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);

                    // add member to list of invited members to the guild
                    guild.addInvited((int)invitedClient.characterId);
                }
                else
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                }
            }
            else
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }

            client.send(reply);
        }
Exemple #25
0
        void handleCharacterCreateMessage(AccountClient client, MessageIn msg)
        {
            string name=msg.readString();
            int hairStyle=msg.readInt8();
            int hairColor=msg.readInt8();
            int gender=msg.readInt8();

            // Avoid creation of character from old clients.
            //            int slot=-1;
            //            if(msg.getUnreadLength()>7)
            //            {
            int slot=msg.readInt8();
            //            }

            MessageOut reply=new MessageOut(Protocol.APMSG_CHAR_CREATE_RESPONSE);

            ISL.Server.Account.Account acc=client.getAccount();

            if(acc==null)
            {
                reply.writeInt8((byte)ErrorMessage.ERRMSG_NO_LOGIN);
            }
            else if(!Program.stringFilter.filterContent(name))
            {
                reply.writeInt8((byte)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else if(Program.stringFilter.findDoubleQuotes(name))
            {
                reply.writeInt8((byte)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else if(hairStyle>mNumHairStyles)
            {
                reply.writeInt8((byte)Create.CREATE_INVALID_HAIRSTYLE);
            }
            else if(hairColor>mNumHairColors)
            {
                reply.writeInt8((byte)Create.CREATE_INVALID_HAIRCOLOR);
            }
            else if(gender>mNumGenders)
            {
                reply.writeInt8((byte)Create.CREATE_INVALID_GENDER);
            }
            else if((name.Length<mMinNameLength)||
                (name.Length>mMaxNameLength))
            {
                reply.writeInt8((byte)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }
            else
            {
                if(Program.storage.doesCharacterNameExist(name))
                {
                    reply.writeInt8((byte)Create.CREATE_EXISTS_NAME);
                    client.send(reply);
                    return;
                }

                // An account shouldn't have more
                // than <account_maxCharacters> characters.
                Dictionary<uint, ISL.Server.Account.Character> chars=acc.getCharacters();

                if(slot<1||slot>mMaxCharacters||!acc.isSlotEmpty((uint)slot))
                {
                    reply.writeInt8((byte)Create.CREATE_INVALID_SLOT);
                    client.send(reply);
                    return;
                }

                if((int)chars.Count>=mMaxCharacters)
                {
                    reply.writeInt8((byte)Create.CREATE_TOO_MUCH_CHARACTERS);
                    client.send(reply);
                    return;
                }

                // TODO: Add race, face and maybe special attributes.

                // Customization of character's attributes...
                List<int> attributes=new List<int>();
                //std::vector<int>(mModifiableAttributes.size(), 0);
                for(uint i = 0;i < mModifiableAttributes.Count;++i)
                {
                    attributes.Add(msg.readInt16());
                }

                int totalAttributes=0;
                for(uint i = 0;i < mModifiableAttributes.Count;++i)
                {
                    // For good total attributes check.
                    totalAttributes+=attributes[(int)i];

                    // For checking if all stats are >= min and <= max.
                    if(attributes[(int)i]<mAttributeMinimum
                        ||attributes[(int)i]>mAttributeMaximum)
                    {
                        reply.writeInt8((byte)Create.CREATE_ATTRIBUTES_OUT_OF_RANGE);
                        client.send(reply);
                        return;
                    }
                }

                if(totalAttributes>mStartingPoints)
                {
                    reply.writeInt8((byte)Create.CREATE_ATTRIBUTES_TOO_HIGH);
                }
                else if(totalAttributes<mStartingPoints)
                {
                    reply.writeInt8((byte)Create.CREATE_ATTRIBUTES_TOO_LOW);
                }
                else
                {
                    Character newCharacter=new Character(name);

                    // Set the initial attributes provided by the client
                    for(uint i = 0;i < mModifiableAttributes.Count;++i)
                    {
                        //TODO schauen was hier genau passieren muss
                        //newCharacter.mAttributes.Add((uint)(mModifiableAttributes[(int)i]), mModifiableAttributes[i]);
                        //newCharacter.mAttributes.Add((uint)mModifiableAttributes[(int)i], attributes[(int)i]);
                    }

                    foreach(KeyValuePair<uint, Attribute> defaultAttributePair in mDefaultAttributes)
                    {
                        //TODO schauen was hier genau passieren muss
                        // newCharacter.mAttributes.Add(defaultAttributePair.Key, defaultAttributePair.Value);
                    }

                    newCharacter.setAccount(acc);
                    newCharacter.setCharacterSlot((uint)slot);
                    newCharacter.setGender(gender);
                    newCharacter.setHairStyle(hairStyle);
                    newCharacter.setHairColor(hairColor);
                    newCharacter.setMapId(Configuration.getValue("char_startMap", 1));
                    Point startingPos=new Point(Configuration.getValue("char_startX", 1024),
                                      Configuration.getValue("char_startY", 1024));
                    newCharacter.setPosition(startingPos);
                    acc.addCharacter(newCharacter);

                    Logger.Write(LogLevel.Information, "Character {0} was created for {1}'s account.", name, acc.getName());

                    Program.storage.flush(acc); // flush changes

                    // log transaction
                    Transaction trans=new Transaction();
                    trans.mCharacterId=(uint)newCharacter.getDatabaseID();
                    trans.mAction=(uint)TransactionMembers.TRANS_CHAR_CREATE;
                    trans.mMessage=acc.getName()+" created character ";
                    trans.mMessage+="called "+name;
                    Program.storage.addTransaction(trans);

                    reply.writeInt8((byte)ErrorMessage.ERRMSG_OK);
                    client.send(reply);

                    // Send new characters infos back to client
                    sendCharacterData(client, chars[(uint)slot]);
                    return;
                }
            }

            client.send(reply);
        }
Exemple #26
0
        void handleGuildKickMember(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_KICK_MEMBER_RESPONSE);
            short guildId=msg.readInt16();
            string user=msg.readString();

            Guild guild=Program.guildManager.findById(guildId);
            Character c=Program.storage.getCharacter(user);

            if(guild!=null&&c!=null)
            {
                if((guild.getUserPermissions(c.getDatabaseID())&(int)(GuildAccessLevel.GAL_KICK))!=0) //TODO Überprüfen ob Vergleich so richtig rum
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                }
                else
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_INSUFFICIENT_RIGHTS);
                }
            }
            else
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
            }

            client.send(reply);
        }
Exemple #27
0
        void handleLoginMessage(AccountClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.APMSG_LOGIN_RESPONSE);

            //Überprüfung ob es sich um einen Login Request handelt
            if(client.status!=AccountClientStatus.CLIENT_LOGIN)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                client.send(reply);
                return;
            }

            int clientVersion=msg.readInt32();

            if(clientVersion<ManaServ.PROTOCOL_VERSION)
            {
                reply.writeInt8((int)Login.LOGIN_INVALID_VERSION);
                client.send(reply);
                return;
            }

            // Check whether the last login attempt for this IP is still too fresh
            IPAddress address=client.getIP();
            DateTime now=DateTime.Now;

            if(mLastLoginAttemptForIP.ContainsKey(address)) //TODO Schauen ob der Vergleich gegen das IPAdress Objekt funktioniert
            {
                DateTime lastAttempt=mLastLoginAttemptForIP[address];
                lastAttempt.AddSeconds(1); //TODO schauen ob hier im Original wirklich Sekunden gemeint sind

                if(now<lastAttempt)
                {
                    reply.writeInt8((int)Login.LOGIN_INVALID_TIME);
                    client.send(reply);
                    return;
                }
            }

            mLastLoginAttemptForIP[address]=now;

            string username=msg.readString();
            string password=msg.readString();

            if(Program.stringFilter.findDoubleQuotes(username))
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
                client.send(reply);
                return;
            }

            uint maxClients=(uint)Configuration.getValue("net_maxClients", 1000);

            if(getClientCount()>=maxClients)
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_SERVER_FULL);
                client.send(reply);
                return;
            }

            // Check if the account exists
            ISL.Server.Account.Account acc=null;

            foreach(ISL.Server.Account.Account tmp in mPendingAccounts)
            {
                if(tmp.getName()==username)
                {
                    acc=tmp;
                    break;
                }
            }

            mPendingAccounts.Remove(acc);

            //TODO Überprüfen ob SHA256 das gewünschte Ergebniss liefert
            if(acc!=null)
            {
                if(SHA256.HashString(acc.getPassword()+acc.getRandomSalt())!=password)
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_INVALID_ARGUMENT);
                    client.send(reply);
                    //delete acc;
                    return;
                }
            }

            if(acc.getLevel()==(int)AccessLevel.AL_BANNED)
            {
                reply.writeInt8((int)Login.LOGIN_BANNED);
                client.send(reply);
                //delete acc;
                return;
            }

            // The client successfully logged in...

            // Set lastLogin date of the account.
            DateTime login=DateTime.Now;
            acc.setLastLogin(login);
            Program.storage.updateLastLogin(acc);

            // Associate account with connection.
            client.setAccount(acc);
            client.status=AccountClientStatus.CLIENT_CONNECTED;

            reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
            addServerInfo(reply);
            client.send(reply); // Acknowledge login

            // Return information about available characters
            Dictionary<uint, Character> chars=acc.getCharacters();

            // Send characters list
            foreach(ISL.Server.Account.Character character in chars.Values)
            {
                sendCharacterData(client, character);
            }
        }
Exemple #28
0
        void handleGuildMemberLevelChange(ChatClient client, MessageIn msg)
        {
            // get the guild, the user to change the permissions, and the new permission
            // check theyre valid, and then change them
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE);
            short guildId = msg.readInt16();
            string user = msg.readString();
            short level = msg.readInt8();

            Guild guild = Program.guildManager.findById(guildId);
            Character c = Program.storage.getCharacter(user);

            if (guild!=null && c!=null)
            {
                int rights = guild.getUserPermissions(c.getDatabaseID()) | level;
                if(Program.guildManager.changeMemberLevel(client, guild, c.getDatabaseID(), rights)==0)
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                    client.send(reply);
                }
            }

            reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE); //TODO Muss das so oder fehlt oben ein return?
            client.send(reply);
        }
Exemple #29
0
        public void serializeCharacterData(MessageOut msg)
        {
            // general character properties
            msg.writeInt8(getAccountLevel());
            msg.writeInt8((int)getGender());
            msg.writeInt8(getHairStyle());
            msg.writeInt8(getHairColor());
            msg.writeInt16(getLevel());
            msg.writeInt16(getCharacterPoints());
            msg.writeInt16(getCorrectionPoints());

            msg.writeInt16(mAttributes.Count);

            //            foreach(KeyValuePair<uint, AttributeValue> pair in mAttributes)
            //            {
            //                msg.writeInt16((Int16)pair.Key);
            //
            //                msg.writeDouble(pair.Value.@base);
            //                msg.writeDouble(pair.Value.modified);
            //            }

            foreach(KeyValuePair<uint, Attribute> pair in mAttributes)
            {
                msg.writeInt16((int)pair.Key);
                msg.writeDouble(pair.Value.getBase());
                msg.writeDouble(pair.Value.getModifiedAttribute());
            }

            // character skills
            msg.writeInt16(getSkillSize());

            foreach(KeyValuePair<int, int> pair in mExperience)
            {
                msg.writeInt16(pair.Key);
                msg.writeInt32(pair.Value);
            }

            // status effects currently affecting the character
            msg.writeInt16(getStatusEffectSize());

            foreach(KeyValuePair<int, int> pair in mStatusEffects)
            {
                msg.writeInt16(pair.Key);
                msg.writeInt16(pair.Value);
            }

            // location
            msg.writeInt16(getMapId());
            Point pos=getPosition();
            msg.writeInt16(pos.x);
            msg.writeInt16(pos.y);

            // kill count
            msg.writeInt16(getKillCountSize());

            foreach(KeyValuePair<int, int> pair in mKillCount)
            {
                msg.writeInt16(pair.Key);
                msg.writeInt32(pair.Value);
            }

            // character specials
            msg.writeInt16(mSpecials.Count);

            foreach(KeyValuePair<int, Special> pair in mSpecials)
            {
                msg.writeInt32(pair.Key);
            }

            // inventory - must be last because size isn't transmitted
            Possessions poss=getPossessions();
            Dictionary< uint, EquipmentItem > equipData=poss.getEquipment();
            msg.writeInt16(equipData.Count); // number of equipment

            foreach(KeyValuePair<uint, EquipmentItem> k in equipData)
            {
                msg.writeInt16((int)k.Key);                 // Equip slot id
                msg.writeInt16((int)k.Value.itemId);         // ItemId
                msg.writeInt16((int)k.Value.itemInstance);   // Item Instance id
            }

            Dictionary< uint, InventoryItem > inventoryData=poss.getInventory();

            foreach(KeyValuePair<uint, InventoryItem> j in inventoryData)
            {
                msg.writeInt16((int)j.Key);           // slot id
                msg.writeInt16((int)j.Value.itemId);   // item id
                msg.writeInt16((int)j.Value.amount);   // amount
            }
        }
Exemple #30
0
        void handleGuildQuit(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_GUILD_QUIT_RESPONSE);
            short guildId = msg.readInt16();
            Guild guild = Program.guildManager.findById(guildId);

            // check for valid guild
            // check the member is in the guild
            // remove the member from the guild
            if (guild!=null)
            {
                if (guild.checkInGuild((int)client.characterId))
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_OK);
                    reply.writeInt16(guildId);

                    // Check if there are no members left, remove the guild channel
                    if (guild.memberCount() == 0)
                    {
                        Program.chatChannelManager.removeChannel(Program.chatChannelManager.getChannelId(guild.getName()));
                    }

                    // guild manager checks if the member is the last in the guild
                    // and removes the guild if so
                    Program.guildManager.removeGuildMember(guild, (int)client.characterId);
                    sendGuildListUpdate(guild.getName(), client.characterName, (int)GuildValues.GUILD_EVENT_LEAVING_PLAYER);
                }
                else
                {
                    reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
                }
            }
            else
            {
                reply.writeInt8((int)ErrorMessage.ERRMSG_FAILURE);
            }

            //client.send(reply);
        }