Thread: Looping (To affect all players) Issue [Delta]

Results 1 to 3 of 3
  1. #1 Looping (To affect all players) Issue [Delta] 
    Registered Member
    Join Date
    Dec 2009
    Posts
    84
    Thanks given
    48
    Thanks received
    25
    Rep Power
    14
    I'm trying to create a custom clan chat for my server, and whenever the server is supposed to send a message to all players under a certain criteria (Only happens when I use a command that involves clan chat), the user disconnects.

    This happens for any clan chat related void that sends messages to multiple players, but I'm just going to include my joiningclan() method and ::joinclan command, because the way they send messages to multiple players is similar to the way the other clan chat related methods are written.

    Command:
    Code:
    if(command.startsWith("joinclan")){
                        String otherPName = command.substring(9);
    					joiningclan(otherPName);
                }


    Void:
    Code:
    	public void joiningclan(String otherPName){
    						
    		//Begins checking your account				
    		if(otherPName.equalsIgnoreCase(playerName))  //If you are trying to join your own clan using the ::joinclan command instead of the ::joinmyclan command
    			{
    				sM("To join your own clan, type ::joinmyclan.");
    				return;
    			}
    		
    		if(inclan != null)  //If you have already joined a clan, and have not left it yet.
    			{
    				sM("You are already in a clan.");
    				return;
    			}
    			
    					//Creates the following so we can check the target account
    					int player = PlayerHandler.getPlayerID(otherPName);
    					client c = (client) server.playerHandler.players[player];
    					
    		//Begins checking the target account			
    		if(c.hasaclan == 0)  //If the target has not created a clan yet
    			{			
    				sM("That player has not created a clan chat yet.");
    				return;
    			}
    			
    		if(!c.inclan.equalsIgnoreCase(""+otherPName+""))  //If the target is not currently in their own clan
    			{
    				sM("That person is not currently in their clan chat.");
    				return;
    			}
    				
    		//Finished all checks for both accounts
    		
    						inclan = (""+otherPName+"");
    						c.inyourclan += 1;
    						
    						if(c.inyourclan > 1)
    							{
    						/*
    							This is called after you have been added to the clan.
    							If you are the only player in the clan, then it skips the following.
    							This makes it so that the server does not check these because there are no players to send the message to.
    							Anything besides this condition should be impossible because of the checks made at the beginning of the void,
    							unless the owner left after the server checked his clan status, and before this check has been made.
    							However, this is either VERY unlikley, or impossible.
    							It is here just in-case, I suppose.
    						*/
    						
    							for (Player p : handler.players) 
    								{
    									
    										if ((p != null) || p.isActive)
    											{  //Weeds out any players who are nulled or in some way glitched.
    									
    												client castOn = (client) p;
    											
    											if (castOn.absX > 0 && castOn.absY > 0 && 
    											   (castOn != null) && !castOn.disconnected) { 
    											   //Another check to make sure that the player is not glitched in any way.
    
    													if(castOn.inclan.equalsIgnoreCase(inclan))
    														{  //Weeds anyone who is not in the same clan as the one you just joined.
    															castOn.sM("@gre@"+playerName+" has joined "+inclan+"'s clan.");
    														}
    												}
    											}
    								}
    							}
    						sM("You have joined "+otherPName+"'s clan chat."); //Notifies the player that the executed command was successful.
    	} //Finally ends the void.


    I explain the way the void works using comments in the code.
    Also, here's the exception the server throws when I execute the command.




    Please help me with this, I've been at this for days and I still haven't found a solution.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Apr 2009
    Posts
    57
    Thanks given
    0
    Thanks received
    0
    Rep Power
    1
    Add me on msn "[email protected]" try n help you out

    CLICK TO GIVE IDEAS FOR THE SERVER

    Rune-Stop in progress 10%
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Jan 2009
    Age
    31
    Posts
    2,661
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    Code:
    public class ClanChatHandler {
    
    	private static final String CLAN_FILES = "data\GameServer\Clans\";
    	private static Clan clans = new Clan[50];
    
    	public static void joinClan(Client c, String name) {
    		if (FileManager.fileExists(CLAN_FILES + name)) {
    			c.sendMessage("Joining clan chat "+name+". Please wait.");
    			add(c,name);
    		} else {
    			c.sendMessage("This player has not created his/her own clan chat yet");
    		}
    	}
    
    	public static void sendClanMessage(Client c, String message) {
    		final Clan clanIndex = clans[c.getClanIndex()];
    		clanIndex.sendMessage(c.playerName,message);
    	}
    
    	private static void add(Client c, String clanName) {
    		final Clan clanIndex = getIndex(clanName);
                     		if (clanIndex != null)
                     			clanIndex.addPlayer(c);
    	}
    
    	private static void remove(Client c, String clanName) {
    		final Clan clanIndex = getIndex(clanName);
                     		if (clanIndex != null)
    			clanIndex.removePlayer(c);
    	}
    	
    	private static void expand() {
    		Clan newClans = new Clan[clans.length + 50];
    		System.arraycopy(clans, 0, newClans, 0, clans.length);
    		clans = newClans;
    	}
    
    	private static Clan getIndex(String s) {
    	int slot = -1;
    		for (int i = 0; i < clans.length; i++) {
    			if (clans[i] == null) {
    				slot = slot == -1 ? i : slot;
    				continue;
    			}
    			if (clans[i].getName().equalsIgnoreCase(s))
    				return clans[i];
    		}
    		slot = slot == -1 ? clans.length + 1 : slot;
    		if (slot > clans.length)
    			expand();
    		clans[slot] = new Clan(s,s,slot);
    		return clans[slot];
    	}
    }
    
    class Clan {
    	
    	private static final int FRAME_INDEX = 18144;
    	private final String NAME;
    	private final String OWNER;
    	private final int INDEX;
            private int size = 0;
    	private final List<Client> players = new LinkedList<Client>();
    
    	protected Clan(final String OWNER, final String NAME, final int INDEX) {
    		this.OWNER = OWNER;
    		this.NAME = NAME;
    		this.INDEX = INDEX;
    	}
    
    	protected int getSize() {
    		return size;
    	}
    
    	protected void addPlayer(Client c) {
    		if (size == 200) {
    			c.sendMessage("Sorry but this clan chat is currently full");
    			return;
    		}
    		for (client p : players) {
    			p.getPA().sendFrame126(c.playerName,FRAME_INDEX + size);
    		}
    		c.setClanIndex(INDEX);
    		players.add(c);
    		++size;
    		updateMenu(c);
    	}
    
    	protected void removePlayer(Client p) {
    		if (players.remove(p)) {
    			--size;
    			updateMenu();
    		}
    	}
    	
    	private void updateMenu(Client c) {
    		int loc = 0;
    		for (client p : players) {
    			c.getPA().sendFrame126(p.playerName,FRAME_INDEX + (loc++));
    		}
    	}
    
    	protected void sendMessage(Client p, String message) {
    		for (Client c : players) {
    			if (c == null) continue;
    				c.sendMessage("[@blu@" + NAME + "@bla@] " + p.playerName + ": @red@" + message); 
    		}
    	}
    
    }
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •