Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.rvgate.arrv.Commands;
- import nl.rvgate.arrv.Channel;
- import nl.rvgate.arrv.Client;
- import nl.rvgate.arrv.Datastore;
- import nl.rvgate.arrv.Modes;
- import nl.rvgate.arrv.Reply;
- public class Join {
- public static final int params = 2;
- public Join(Client cl, String channels){
- new Join(cl, channels, "");
- }
- public Join(Client cl, String channels, String keys){
- String[] keysarray = keys.split(",");
- String[] channelsarray = channels.split(",");
- int index = 0;
- for(String channelstring : channelsarray){
- Channel channel = Datastore.getChannelByName(channelstring);
- String key = "";
- try {
- key = keysarray[index];
- } catch (Exception E){
- key = "";
- }
- if(channel == null){
- Reply reply = new Reply(Reply.ERR_NOSUCHCHANNEL, cl);
- reply.set(channelstring+" :No such channel");
- cl.send(reply);
- continue;
- }
- if(channel.hasMode(Modes.CHANNEL_INVITEONLY)){
- if(!channel.isInvited(cl)){
- Reply reply = new Reply(Reply.ERR_INVITEONLYCHAN, cl);
- reply.set(channelstring+" :Cannot join channel (+i)");
- cl.send(reply);
- continue;
- }
- }
- if(channel.isBanned(cl)){
- Reply reply = new Reply(Reply.ERR_BANNEDFROMCHAN, cl);
- reply.set(channelstring+" :Cannot join channel (+b)");
- cl.send(reply);
- continue;
- }
- if(channel.hasMode(Modes.CHANNEL_PASSWORD)){
- if(!key.equals(channel.getKey())){
- Reply reply = new Reply(Reply.ERR_BADCHANNELKEY, cl);
- reply.set(channelstring+" :Cannot join channel (+k)");
- cl.send(reply);
- continue;
- }
- }
- channel.registerClient(cl);
- // Send notice
- // Notify user he has joined
- Reply joinreply = new Reply(cl);
- joinreply.set("JOIN "+channelstring);
- cl.send(joinreply);
- // Send topic
- Reply reply = null;
- if(channel.getTopic() == null){
- reply = new Reply(Reply.RPL_NOTOPIC, cl);
- reply.set(channelstring+" :No topic is set");
- cl.send(reply);
- } else {
- reply = new Reply(Reply.RPL_TOPIC, cl);
- reply.set(channelstring+" :"+channel.getTopic());
- cl.send(reply);
- }
- // Send userlist
- String str = "";
- for(Client client : channel.getClients()){
- str = str + " " + client.getNickname();
- }
- reply = new Reply(Reply.RPL_NAMREPLY, cl);
- reply.set(channelstring + " :" + str);
- cl.send(reply);
- reply = new Reply(Reply.RPL_ENDOFNAMES, cl);
- reply.set(channelstring + " :End of /NAMES list");
- cl.send(reply);
- // Notify all other users in channel that he joined
- for(Client client : channel.getClients()){
- if(client != cl) client.send(joinreply);
- }
- index++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement