Thread: Save on Network Disconnection?

Results 1 to 6 of 6
  1. #1 Save on Network Disconnection? 
    Registered Member
    Join Date
    Feb 2012
    Posts
    264
    Thanks given
    88
    Thanks received
    34
    Rep Power
    0
    I encountered this bug while dupe-testing on my server. If you do an action that gives another player an item, for example dropping an item, and then disconnect your router and put it back in, your account will load on the last time it was saved.

    The issue is, how would I prevent rollbacks as a whole? I was thinking creating a separate thread and saving all accounts in that one, but that would eat up my memory.

    I also tried using this:

    Code:
    	@Override
    	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    			throws Exception {
    		Player player = session.getPlayer();
    		if (player != null) SerializeSave.savePlayer(player);
    	}
    Code:
    @Override
    	public void run() {
    		Thread.currentThread().setName("NodeWorker");
    		Node n = null;
    		while (true) {
    			try {
    			while (!AWAITING_ADDING.isEmpty()) {
    				n = AWAITING_ADDING.poll();
    				if (n instanceof Player) {
    					try {
    						Player player = PLAYER_LOADER.load(PLAYER_LOADER.checkLogin(n));
    						if (player != null) {
    							if (player.getIOSession().isInLobby()) {
    								LOBBY_PLAYERS.add(player);
    								PLAYER_NAME_MAP.put("+lobby>" + player.getCredentials().getUsername(), player);
    							} else {
    								LOBBY_PLAYERS.remove(player);
    								PLAYER_NAME_MAP.remove("+lobby>" + player.getCredentials().getUsername());
    								if (getPlayer(player.getCredentials().getUsername()) == null) {
    									PLAYERS.add(player);
    									PLAYER_NAME_MAP.put(player.getCredentials().getUsername(), player); 
    								} else {
    									player.getIOSession().getChannel().disconnect();
    									continue;
    								}
    							}
    							player.init();
    							System.out.println("Player " + player.getCredentials().getUsername() + " connected: [" + player.getIndex() + ", " + PLAYERS.size() + "].");
    						}
    					} catch (Throwable t) {
    						t.printStackTrace();
    					}
    				} else if (n instanceof NPC) {
    					NPC npc = NPC_LOADER.load(NPC_LOADER.checkLogin(n));
    					if (npc != null) {
    						npc.init();
    						NPCS.add(npc);
    					}
    				} else if (n instanceof GameObject) {
    					OBJECT_LOADER.load(OBJECT_LOADER.checkLogin(n));
    				} else {
    					throw new IllegalStateException("Unsupported node - " + n.getClass().getSimpleName());
    				}
    			}
    			while (!AWAITING_REMOVAL.isEmpty()) {
    				n = AWAITING_REMOVAL.poll();
    				if (n instanceof Player) {
    					DISCONNECTED_PLAYERS.add((Player) n);
    				} else if (n instanceof NPC) {
    					NPC npc = NPC_LOADER.save(n).clear();
    					if (npc != null) {
    						NPCS.remove(npc);
    					}
    				} else if (n instanceof GameObject) {
    					OBJECT_LOADER.save(n);
    				}
    			}
    			for (Iterator<Player> it = DISCONNECTED_PLAYERS.iterator(); it.hasNext();) {
    				Player p = it.next();
    				boolean isLobby = LOBBY_PLAYERS.get(p.getIndex()) == p;
    				if (!isLobby && PLAYERS.get(p.getIndex()) != p) {
    					PLAYER_NAME_MAP.remove("+lobby>" + p.getCredentials().getUsername());
    					PLAYER_NAME_MAP.remove(p.getCredentials().getUsername());
    					it.remove(); //Prevent random resets.
    					continue;
    				}
    				Player player = PLAYER_LOADER.save(p);
    				if (player == null) {
    					//If the player isn't ready to be removed yet.
    					continue;
    				}
    				if (isLobby) {
    					LOBBY_PLAYERS.remove(player.clearLobby());
    					PLAYER_NAME_MAP.remove("+lobby>" + player.getCredentials().getUsername());
    				}
    				if (PLAYERS.get(player.getIndex()) == player) {
    					PLAYERS.remove(player.clear());
    					PLAYER_NAME_MAP.remove(player.getCredentials().getUsername());
    					System.out.println("Player " + player.getCredentials().getUsername() + " disconnected: [" + player.getIndex() + ", " + PLAYERS.size() + "].");
    				}
    				it.remove();
    			}
    			} catch (Throwable t) {
    				t.printStackTrace();
    			}
    			try {
    				Thread.sleep(600);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    Is what is used to add the player to the list of online players, and remove them.

    However, it was ineffective . What should I do?
    Reply With Quote  
     

  2. #2  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    client.java search "destroy" under that method add that player savingshit.
    Reply With Quote  
     

  3. #3  
    Member
    Nour's Avatar
    Join Date
    May 2007
    Posts
    472
    Thanks given
    127
    Thanks received
    61
    Rep Power
    569
    Your post is a little vague, you might want to add a few more details on the problem if you want someone to give you some accurate help
    RIP Emps-scape 2006-2013.
    [SPOIL]
    [/SPOIL]

    i need 2 herd sum bots
    i need 2 steal sum zombies
    i need 2 open many slots
    to hold my ****in zombies
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Feb 2012
    Posts
    264
    Thanks given
    88
    Thanks received
    34
    Rep Power
    0
    Not using Project Insanity, nor Hyperion or Apollo/anything released.

    What info should I add? This is what I do for the dupe to happen:

    Spawn 11694, save so my character file has it. Drop 11694, then log back in, plug out my router and plug it back in. In my inventory, I will have 11694, and the ground item manager also shows 11694 in a few ticks.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Feb 2012
    Posts
    264
    Thanks given
    88
    Thanks received
    34
    Rep Power
    0
    Code:
    @Override
    	public void run() {
    		Thread.currentThread().setName("NodeWorker");
    		Node n = null;
    		while (true) {
    			try {
    			while (!AWAITING_ADDING.isEmpty()) {
    				n = AWAITING_ADDING.poll();
    				if (n instanceof Player) {
    					try {
    						Player player = PLAYER_LOADER.load(PLAYER_LOADER.checkLogin(n));
    						if (player != null) {
    							if (player.getIOSession().isInLobby()) {
    								LOBBY_PLAYERS.add(player);
    								PLAYER_NAME_MAP.put("+lobby>" + player.getCredentials().getUsername(), player);
    							} else {
    								LOBBY_PLAYERS.remove(player);
    								PLAYER_NAME_MAP.remove("+lobby>" + player.getCredentials().getUsername());
    								if (getPlayer(player.getCredentials().getUsername()) == null) {
    									PLAYERS.add(player);
    									PLAYER_NAME_MAP.put(player.getCredentials().getUsername(), player); 
    								} else {
    									player.getIOSession().getChannel().disconnect();
    									continue;
    								}
    							}
    							player.init();
    							System.out.println("Player " + player.getCredentials().getUsername() + " connected: [" + player.getIndex() + ", " + PLAYERS.size() + "].");
    						}
    					} catch (Throwable t) {
    						t.printStackTrace();
    					}
    				} else if (n instanceof NPC) {
    					NPC npc = NPC_LOADER.load(NPC_LOADER.checkLogin(n));
    					if (npc != null) {
    						npc.init();
    						NPCS.add(npc);
    					}
    				} else if (n instanceof GameObject) {
    					OBJECT_LOADER.load(OBJECT_LOADER.checkLogin(n));
    				} else {
    					throw new IllegalStateException("Unsupported node - " + n.getClass().getSimpleName());
    				}
    			}
    			while (!AWAITING_REMOVAL.isEmpty()) {
    				n = AWAITING_REMOVAL.poll();
    				if (n instanceof Player) {
    					DISCONNECTED_PLAYERS.add((Player) n);
    				} else if (n instanceof NPC) {
    					NPC npc = NPC_LOADER.save(n).clear();
    					if (npc != null) {
    						NPCS.remove(npc);
    					}
    				} else if (n instanceof GameObject) {
    					OBJECT_LOADER.save(n);
    				}
    			}
    			for (Iterator<Player> it = DISCONNECTED_PLAYERS.iterator(); it.hasNext();) {
    				Player p = it.next();
    				boolean isLobby = LOBBY_PLAYERS.get(p.getIndex()) == p;
    				if (!isLobby && PLAYERS.get(p.getIndex()) != p) {
    					PLAYER_NAME_MAP.remove("+lobby>" + p.getCredentials().getUsername());
    					PLAYER_NAME_MAP.remove(p.getCredentials().getUsername());
    					it.remove(); //Prevent random resets.
    					continue;
    				}
    				Player player = PLAYER_LOADER.save(p);
    				if (player == null) {
    					//If the player isn't ready to be removed yet.
    					continue;
    				}
    				if (isLobby) {
    					LOBBY_PLAYERS.remove(player.clearLobby());
    					PLAYER_NAME_MAP.remove("+lobby>" + player.getCredentials().getUsername());
    				}
    				if (PLAYERS.get(player.getIndex()) == player) {
    					PLAYERS.remove(player.clear());
    					PLAYER_NAME_MAP.remove(player.getCredentials().getUsername());
    					System.out.println("Player " + player.getCredentials().getUsername() + " disconnected: [" + player.getIndex() + ", " + PLAYERS.size() + "].");
    				}
    				it.remove();
    			}
    			} catch (Throwable t) {
    				t.printStackTrace();
    			}
    			try {
    				Thread.sleep(600);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    Is what is used to add the player to the list of online players, and remove them.
    Reply With Quote  
     

  6. #6  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Posts
    2,622
    Thanks given
    201
    Thanks received
    813
    Rep Power
    1462
    Isnt this emperors source? If so wrong section .
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    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

Similar Threads

  1. Disconnection
    By Flaunter in forum Help
    Replies: 2
    Last Post: 01-15-2012, 10:41 PM
  2. [PI] Random Disconnection.
    By myK- in forum Help
    Replies: 6
    Last Post: 12-17-2010, 12:03 AM
  3. [PI] Disconnection Problem
    By Jason in forum Help
    Replies: 7
    Last Post: 10-27-2010, 03:21 AM
  4. Need help with disconnection
    By mage bow v2 in forum Help
    Replies: 3
    Last Post: 03-12-2010, 01:05 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •