Пример #1
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);
        }
Пример #2
0
        void handleListChannelsMessage(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_LIST_CHANNELS_RESPONSE);

            List<ChatChannel> channels=Program.chatChannelManager.getPublicChannels();

            foreach(ChatChannel channel in channels)
            {
                reply.writeString(channel.getName());
                reply.writeInt16(channel.getUserList().Count);
            }

            client.send(reply);

            // log transaction
            Transaction trans=new Transaction();
            trans.mCharacterId = client.characterId;
            trans.mAction =(uint)TransactionMembers.TRANS_CHANNEL_LIST;
            Program.storage.addTransaction(trans);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        void sendGuildRejoin(ChatClient client)
        {
            // Get list of guilds and check what rights they have.
            List<Guild> guilds=Program.guildManager.getGuildsForPlayer((int)client.characterId);

            foreach(Guild guild in guilds)
            {
                int permissions = guild.getUserPermissions((int)client.characterId);
                string guildName = guild.getName();

                // Tell the client what guilds the character belongs to and their permissions
                MessageOut msg=new MessageOut(Protocol.CPMSG_GUILD_REJOIN);
                msg.writeString(guildName);
                msg.writeInt16(guild.getId());
                msg.writeInt16(permissions);

                // get channel id of guild channel
                ChatChannel channel = joinGuildChannel(guildName, client);

                // send the channel id for the autojoined channel
                msg.writeInt16(channel.getId());
                msg.writeString(channel.getAnnouncement());

                client.send(msg);

                sendGuildListUpdate(guildName, client.characterName, (int)ISL.Server.Enums.GuildValues.GUILD_EVENT_ONLINE_PLAYER);
            }
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #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);
        }
Пример #9
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);
 }
Пример #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);
 }
Пример #11
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);
            }
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
        void handleListChannelUsersMessage(ChatClient client, MessageIn msg)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_LIST_CHANNELUSERS_RESPONSE);

            string channelName=msg.readString();
            ChatChannel channel=Program.chatChannelManager.getChannel(channelName);

            if(channel!=null)
            {
                reply.writeString(channel.getName());

                List<ChatClient> users=channel.getUserList();

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

                client.send(reply);
            }

            // log transaction
            Transaction trans=new Transaction();
            trans.mCharacterId=client.characterId;
            trans.mAction=(uint)TransactionMembers.TRANS_CHANNEL_USERLIST;
            Program.storage.addTransaction(trans);
        }
Пример #15
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);
        }
Пример #16
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());
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
0
        void handleWhoMessage(ChatClient client)
        {
            MessageOut reply=new MessageOut(Protocol.CPMSG_WHO_RESPONSE);

            foreach(string id in mPlayerMap.Keys)
            {
                reply.writeString(id);
            }

            client.send(reply);
        }