Example #1
0
        public bool addUser(ChatClient user)
        {
            // First user is the channel owner
            if(mRegisteredUsers.Count()<1)
            {
                mOwner=user.characterName;
                setUserMode(user, (byte)'o');
            }

            // Check if the user already exists in the channel
            foreach(ChatClient chatClient in mRegisteredUsers)
            {
                if(chatClient.characterName==user.characterName)
                {
                    return false;
                }
            }

            mRegisteredUsers.Add(user);
            user.channels.Add(this);

            // set user as logged in
            setUserMode(user, (byte)'l');

            // if owner has rejoined, give them ops
            if(user.characterName==mOwner)
            {
                setUserMode(user, (byte)'o');
            }

            return true;
        }
Example #2
0
        public int changeMemberLevel(ChatClient player, Guild guild, int playerId, int level)
        {
            if(guild.checkInGuild((int)player.characterId)&&guild.checkInGuild(playerId))
            {
                int playerLevel=guild.getUserPermissions((int)player.characterId);

                if(playerLevel==(int)GuildAccessLevel.GAL_OWNER)
                {
                    // player can modify anyones permissions
                    setUserRights(guild, playerId, level);
                    return 0;
                }
            }

            return -1;
        }
Example #3
0
        void handlePrivMsgMessage(ChatClient client, MessageIn msg)
        {
            string user = msg.readString();
            string text = msg.readString();

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

            // We seek the player to whom the message is told and send it to her/him.
            sayToPlayer(client, user, text);
        }
Example #4
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());
        }
Example #5
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);
        }
Example #6
0
        void handleKickUserMessage(ChatClient client, MessageIn msg)
        {
            short channelId=msg.readInt16();
            ChatChannel channel=Program.chatChannelManager.getChannel(channelId);

            if(channelId==0||channel!=null)
            {
                // invalid channel
                return;
            }

            if(channel.getUserMode(client).IndexOf('o')==-1)
            {
                // invalid permissions
                return;
            }

            // get the user whos being kicked
            string user=msg.readString();

            if(channel.removeUser(getClient(user)))
            {
                string ss=client.characterName+":"+user;
                warnUsersAboutPlayerEventInChat(channel, ss, (int)ChatValues.CHAT_EVENT_KICKED_PLAYER);
            }

            // log transaction
            Transaction trans=new Transaction();
            trans.mCharacterId=client.characterId;
            trans.mAction=(uint)TransactionMembers.TRANS_CHANNEL_KICK;
            trans.mMessage="User kicked "+user;
            Program.storage.addTransaction(trans);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
0
 void updateInfo(ChatClient client, int partyId)
 {
     Character character=Program.storage.getCharacter(client.characterName);
     GameServerHandler.sendPartyChange(character, partyId);
 }
Example #11
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);
        }
Example #12
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);
            }
        }
Example #13
0
        void sayToPlayer(ChatClient computer, string playerName, string text)
        {
            Logger.Write(LogLevel.Debug, computer.characterName+" says to "+playerName+": "+text);

            // Send it to the being if the being exists
            MessageOut result=new MessageOut(Protocol.CPMSG_PRIVMSG);
            result.writeString(computer.characterName);
            result.writeString(text);

            foreach(NetComputer client in clients)
            {
                if(client is ChatClient)
                {
                    client.send(result);
                }
            }
        }
Example #14
0
        void removeUserFromParty(ChatClient client)
        {
            if (client.party!=null)
            {
                client.party.removeUser(client.characterName);
                informPartyMemberQuit(client);

                // if theres less than 1 member left, remove the party
                if (client.party.userCount() < 1)
                {
                    client.party = null;
                }
            }
        }
Example #15
0
        ChatChannel joinGuildChannel(string guildName, ChatClient client)
        {
            // Automatically make the character join the guild chat channel
            ChatChannel channel = Program.chatChannelManager.getChannel(guildName);

            if (channel==null)
            {
                // Channel doesnt exist so create it
                int channelId = Program.chatChannelManager.createNewChannel(guildName, "Guild Channel", "", false);
                channel=Program.chatChannelManager.getChannel(channelId);
            }

            // Add user to the channel
            if (channel.addUser(client))
            {
                // 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);
            }

            return channel;
        }
Example #16
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);
        }
Example #17
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);
        }
Example #18
0
        void deletePendingClient(ChatClient c)
        {
            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
            c.disconnect(msg);
        }
Example #19
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);
        }
Example #20
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);
            }
        }
Example #21
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);
        }
Example #22
0
        void handleChatMessage(ChatClient client, MessageIn msg)
        {
            string text = msg.readString();

            // Pass it through the slang filter (false when it contains bad words)
            if (!Program.stringFilter.filterContent(text))
            {
                warnPlayerAboutBadWords(client);
                return;
            }

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

            if (channel!=null)
            {
            Logger.Write(LogLevel.Debug, "{0} says in channel {1}: {2}", client.characterName, channelId, text);

                MessageOut result=new MessageOut(Protocol.CPMSG_PUBMSG);
                result.writeInt16(channelId);
                result.writeString(client.characterName);
                result.writeString(text);
                sendInChannel(channel, result);
            }

            // log transaction
            Transaction trans=new Transaction();
            trans.mCharacterId = client.characterId;
            trans.mAction=(uint)TransactionMembers.TRANS_MSG_PUBLIC;
            trans.mMessage = "User said " + text;
            Program.storage.addTransaction(trans);
        }
Example #23
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);
        }
Example #24
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);
 }
Example #25
0
        void handleModeChangeMessage(ChatClient client, MessageIn msg)
        {
            short channelId=msg.readInt16();
            ChatChannel channel=Program.chatChannelManager.getChannel(channelId);

            if(channelId==0||channel!=null)
            {
                // invalid channel
                return;
            }

            if(channel.getUserMode(client).IndexOf('o')==-1)
            {
                // invalid permissions
                return;
            }

            // get the user whos mode has been changed
            string user=msg.readString();

            // get the mode to change to
            byte mode=msg.readInt8();
            channel.setUserMode(getClient(user), mode);

            // set the info to pass to all channel clients
            string info=client.characterName+":"+user+":"+mode;

            warnUsersAboutPlayerEventInChat(channel, info, (int)ChatValues.CHAT_EVENT_MODE_CHANGE);

            // log transaction
            Transaction trans=new Transaction();
            trans.mCharacterId=client.characterId;
            trans.mAction=(uint)TransactionMembers.TRANS_CHANNEL_MODE;
            trans.mMessage="User mode ";
            trans.mMessage+=mode+" set on "+user;
            Program.storage.addTransaction(trans);
        }
Example #26
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);
 }
Example #27
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);
        }
Example #28
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);
        }
Example #29
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);
        }
Example #30
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);
        }