Thread: Fix afther a while cant login

Results 1 to 5 of 5
  1. #1 Fix afther a while cant login 
    Registered Member
    Mocro's Avatar
    Join Date
    Nov 2007
    Posts
    532
    Thanks given
    28
    Thanks received
    11
    Rep Power
    125
    after a while ppl cant login they get error login in the game

    how i fix
     

  2. #2  
    Donator

    Pointzero's Avatar
    Join Date
    Jan 2008
    Posts
    548
    Thanks given
    1
    Thanks received
    2
    Rep Power
    86
    Have you got a set ammount of players allowed on at one time?
    “If at first, the idea is not absurd, then there is no hope for it” - Albert Einstein
     

  3. #3  
    Nima304
    Guest
    show us a pic, and show us the run method in server.java

    I had the same problem, I might be able to help
     

  4. #4  
    Registered Member
    Mocro's Avatar
    Join Date
    Nov 2007
    Posts
    532
    Thanks given
    28
    Thanks received
    11
    Rep Power
    125
    Quote Originally Posted by Nima304 View Post
    show us a pic, and show us the run method in server.java

    I had the same problem, I might be able to help
    here you go:

    Code:
    import java.net.*;
    import java.io.*;
    import java.util.*;
    
    public class server implements Runnable {
    
    	public server() {
    	}
    
    	// TODO: yet to figure out proper value for timing, but 500 seems good
    	
    	public static final int cycleTime = 500;
    	public static int delay = 50;
    	public static long delayUpdate = 0, lastRunite = 0;	
    	public static int maxPlayers = 60;
    	public static int uptime;
    	
    	public String connectedFrom;
    	public static String hostAdress;	
    	public static int MaxConnections = 100000;
    	public static int[] ConnectionCount = new int[MaxConnections];
    	public static ArrayList<String> connections = new ArrayList<String>();
    	public static String[] Connections = new String[MaxConnections];	
    	public static ArrayList<String> banned = new ArrayList<String>();
    	
    	public static void main(java.lang.String args[]) {
    		try
            {
    			File f = new File("server.ini");
    			if(!f.exists()){
    				misc.println("server.ini doesn't exist!");
    			}
    			Properties properties = new Properties();
     			Properties p = new Properties();
    			p.load(new FileInputStream("./server.ini"));
    			serverlistenerPort = Integer.parseInt(p.getProperty("Port").trim());
    		} catch(Exception e){
    			misc.println("Error loading settings");
    			e.printStackTrace();
    		}	
    		BanManager.Initialize();
    		clientHandler = new server();
    		(new Thread(clientHandler)).start();			// launch server listener
    		playerHandler = new PlayerHandler();
    		npcHandler = new NPCHandler();
    		itemHandler = new ItemHandler();
    		shopHandler = new ShopHandler();
    		GraphicsHandler = new GraphicsHandler();
    
    		int waitFails = 0;
    		long lastTicks = System.currentTimeMillis();
    		long totalTimeSpentProcessing = 0;
    		int cycle = 0;
    		while(!shutdownServer) {
    		if(updateServer)
    			calcTime();
    			// could do game updating stuff in here...
    			// maybe do all the major stuff here in a big loop and just do the packet
    			// sending/receiving in the client subthreads. The actual packet forming code
    			// will reside within here and all created packets are then relayed by the subthreads.
    			// This way we avoid all the sync'in issues
    			// The rough outline could look like:
    			uptime++;
    			playerHandler.process();			// updates all player related stuff
    			npcHandler.process();
    			itemHandler.process();
    			shopHandler.process();
                System.gc();
    	
    			// taking into account the time spend in the processing code for more accurate timing
    			long timeSpent = System.currentTimeMillis() - lastTicks;
    			totalTimeSpentProcessing += timeSpent;
    			if(timeSpent >= cycleTime) {
    				timeSpent = cycleTime;
    				if(++waitFails > 100) {
    					//shutdownServer = true;
    					misc.println("[KERNEL]: machine is too slow to run this server!");
    				}
    			}
    			try {
    				Thread.sleep(cycleTime-timeSpent);
    			} catch(java.lang.Exception _ex) { }
    			lastTicks = System.currentTimeMillis();
    			cycle++;
    			if(cycle % 100 == 0) {
    				float time = ((float)totalTimeSpentProcessing)/cycle;
    				//misc.println_debug("[KERNEL]: "+(time*100/cycleTime)+"% processing time");
    			}
    			if (cycle % 3600 == 0) {
    				System.gc();
    			}
    			if (ShutDown == true) {
    				if (ShutDownCounter >= 100) {
    					shutdownServer = true;
    				}
    				ShutDownCounter++;
    			}
    		}
    		// shut down the server
    		playerHandler.destruct();
    		clientHandler.killServer();
    		clientHandler = null;
    	}	
    
    	public static server clientHandler = null;			// handles all the clients
    	public static java.net.ServerSocket clientListener = null;
    	public static boolean shutdownServer = false;		// set this to true in order to shut down and kill the server
    	public static boolean shutdownClientHandler;			// signals ClientHandler to shut down
    	public static int serverlistenerPort; //43594=default
    
    	public static PlayerHandler playerHandler = null;
    	public static NPCHandler npcHandler = null;
    	public static ItemHandler itemHandler = null;
    	public static ShopHandler shopHandler = null;
    	public static GraphicsHandler GraphicsHandler = null;
    
    	public int checkbannedips()
    	{
    		try
    		{
    			BufferedReader in = new BufferedReader(new FileReader("data/bannedips.txt"));
    			String data = null;
    			while ((data = in.readLine()) != null)
    			{
    				if (connectingHost.equalsIgnoreCase(data))
    				{
    					return 5;
    				}
    			}
    		}
    		catch (IOException e)
    		{
    			System.out.println("Critical error while checking banned ips!");
    			e.printStackTrace();
    		}
    		return 0;
    	}	
    	
    	public String connectingHost = "";
    	
    	public Socket acceptSocketSafe(ServerSocket x) { //Anti-nuller by Slysoft
    	   boolean socketFound = false;
    	   Socket s = null;
    	   do {
    	      try {
    	      s = x.accept();
    	      int i = s.getInputStream().read();
    	      if ((i & 0xFF) == 14) {
    	        socketFound = true;
    	      }
    	   } catch (Exception e) {
    	   }
    	} while (!socketFound);
    
    	return s;
    	}	
    	
    	public void run() {
    		// setup the listener
    		try {
    			shutdownClientHandler = false;
    			clientListener = new java.net.ServerSocket(serverlistenerPort, 1,
    					null);
    			misc.println("BishScape is: ONLINE!");
    			while (true) {
    				try {
    					java.net.Socket s = acceptSocketSafe(clientListener);
    					s.setTcpNoDelay(true);
    					connectingHost = s.getInetAddress().getHostAddress();
    					String connectingHost = s.getInetAddress().getHostAddress();					
    					checkbannedips();
    					if ( /*
    					 * connectingHost.startsWith("localhost") ||
    					 * connectingHost.equals("127.0.0.1")
    					 */true) {
    						if (connectingHost.contains("74-129-182-147.dhcp.insightbb.com")) {
    							misc.println("Checking Server Status...");
    							s.close();
    						} else {
    							connections.add(connectingHost);
    							if (checkHost(connectingHost) && checkbannedips() != 5 && !BanManager.BannedAddress(connectingHost))  {
    								misc.println("Connection from "
    										+ connectingHost + ":" + s.getPort());
    							playerHandler.newPlayerClient(s, connectingHost);
    							} else {
    								misc.println("ClientHandler: Rejected "
    										+ connectingHost + ":" + s.getPort());
    								s.close();
    							}
    						}
    					} else {
    						misc.println("ClientHandler: Rejected "
    								+ connectingHost + ":" + s.getPort());
    						s.close();
    					}
    					if ((delayUpdate > 0)
    							&& (System.currentTimeMillis() > delayUpdate)) {
    						delay = 50;
    						delayUpdate = 0;
    					}
    					Thread.sleep(100);
    				} catch (Exception e) {
    					//logError(e.getMessage());
    				}
    			}
    		} catch (java.io.IOException ioe) {
    			if (!shutdownClientHandler) {
    				misc.println("Server is already in use.");
    			} else {
    				misc.println("ClientHandler was shut down.");
    			}
    		}
    	}
    	
    	public boolean checkHost(String host) {
    		for (String h : banned) {
    			if (h.equals(host))
    				return false;
    		}
    		int num = 0;
    		for (String h : connections) {
    			if (host.equals(h)) {
    				num++;
    			}
    		}
    		return true;
    	}	
    	
    	public static void killServer() {
    		try {
    			shutdownClientHandler = true;
    			if(clientListener != null) clientListener.close();
    			clientListener = null;
    		} catch(java.lang.Exception __ex) {
    			__ex.printStackTrace();
    		}
    	}
    	
    	public static void calcTime() {
    		long curTime = System.currentTimeMillis();
    		updateSeconds = 180 - ((int)(curTime - startTime) / 1000);
    		if(updateSeconds == 0) {
    			shutdownServer = true;
    		}
    	}
    
    	public static boolean updateServer = false;
    	public static int updateSeconds = 180; //180 because it doesnt make the time jump at the start :P
    	public static long startTime;	
    	
    	public static boolean ShutDown = false;
    	public static int ShutDownCounter = 0;
    }
    and i think when ppl cant login anymore i get null error faitel somthing im not sure tough
     

  5. #5  
    Nima304
    Guest
    your run is fine, just that you have 60 as the max player, so if your server is nulling itself it wont let the players log in after that amount

    alos, take a picture and post it of the fatal error
     


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
  •