Changeset a89e5107360c444563dcc1f31af8593ffdafc8a6
- Timestamp:
- 08/05/07 11:16:18 (1 year ago)
- git-parent:
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/net/driftingsouls/ds2/server/entities/StatShips.java
r1edfb5b ra89e510 24 24 import javax.persistence.Table; 25 25 26 import net.driftingsouls.ds2.server.ContextCommon; 27 import net.driftingsouls.ds2.server.framework.ContextMap; 28 26 29 /** 27 30 * Ein Statistikeintrag zur Schiffszahl und zur Crewmenge in DS … … 46 49 public StatShips() { 47 50 //EMPTY 51 } 52 53 /** 54 * Erstellt einen neuen Statistikeintrag fuer den aktuellen Tick 55 * @param shipCount Die Schiffsanzahl 56 * @param crewCount Die Crewanzahl 57 */ 58 public StatShips(long shipCount, long crewCount) { 59 this.tick = ContextMap.getContext().get(ContextCommon.class).getTick(); 60 this.shipCount = shipCount; 61 this.crewCount = crewCount; 48 62 } 49 63 src/net/driftingsouls/ds2/server/tick/regular/RestTick.java
r7277737 ra89e510 21 21 import java.sql.Blob; 22 22 import java.util.ArrayList; 23 import java.util.Iterator; 23 24 import java.util.List; 24 25 … … 30 31 import net.driftingsouls.ds2.server.comm.PM; 31 32 import net.driftingsouls.ds2.server.config.Systems; 33 import net.driftingsouls.ds2.server.entities.Jump; 34 import net.driftingsouls.ds2.server.entities.StatShips; 32 35 import net.driftingsouls.ds2.server.entities.User; 33 36 import net.driftingsouls.ds2.server.framework.Common; … … 62 65 private void doJumps() { 63 66 try { 64 Database db = getContext().getDatabase();67 org.hibernate.Session db = getContext().getDB(); 65 68 66 69 this.log("Sprungantrieb"); 67 SQLQuery jump = db.query("SELECT id,x,y,system,shipid FROM jumps"); 68 while( jump.next() ) { 69 this.log( jump.getInt("shipid")+" springt nach "+jump.getInt("system")+":"+jump.getInt("x")+"/"+jump.getInt("y")); 70 71 db.update("UPDATE ships SET x=",jump.getInt("x"),",y=",jump.getInt("y"),",system=",jump.getInt("system")," WHERE id>0 AND id=",jump.getInt("shipid")," OR docked='",jump.getInt("shipid"),"' OR docked='l ",jump.getInt("shipid"),"'"); 72 db.update("DELETE FROM jumps WHERE id=",jump.getInt("id")); 73 } 74 jump.free(); 70 List jumps = db.createQuery("from Jump as j inner join fetch j.ship").list(); 71 for( Iterator iter=jumps.iterator(); iter.hasNext(); ) { 72 Jump jump = (Jump)iter.next(); 73 74 this.log( jump.getShip().getId()+" springt nach "+jump.getLocation()); 75 76 jump.getShip().setSystem(jump.getSystem()); 77 jump.getShip().setX(jump.getX()); 78 jump.getShip().setY(jump.getY()); 79 80 db.createQuery("update Ship set x= :x, y= :y, system= :system where docked in (:dock,:land)") 81 .setInteger("x", jump.getX()) 82 .setInteger("y", jump.getY()) 83 .setInteger("system", jump.getSystem()) 84 .setString("dock", Integer.toString(jump.getShip().getId())) 85 .setString("land", "l "+jump.getShip().getId()) 86 .executeUpdate(); 87 88 db.delete(jump); 89 } 75 90 } 76 91 catch( Exception e ) { … … 86 101 private void doStatistics() { 87 102 try { 88 Database db = getContext().getDatabase();103 org.hibernate.Session db = getDB(); 89 104 90 105 this.log(""); 91 106 this.log("Erstelle Statistiken"); 92 107 93 int shipcount = db.first("SELECT count(*) count FROM ships WHERE id>0 AND owner>1").getInt("count");94 long crewcount = db.first("SELECT sum(crew) totalcrew FROM ships WHERE id>0 AND owner > 0").getLong("totalcrew");95 int tick = getContext().get(ContextCommon.class).getTick();96 97 db. update("INSERT INTO stats_ships (tick,shipcount,crewcount) VALUES (",tick,",",shipcount,",",crewcount,")");108 long shipcount = (Long)db.createQuery("select count(*) from Ship where id>0 and owner>0").iterate().next(); 109 long crewcount = (Long)db.createQuery("select sum(crew) from Ship where id>0 and owner>0").iterate().next(); 110 111 StatShips stat = new StatShips(shipcount, crewcount); 112 db.persist(stat); 98 113 } 99 114 catch( Exception e ) { … … 349 364 @Override 350 365 protected void tick() { 351 Database db = getContext().getDatabase(); 366 Database database = getContext().getDatabase(); 367 org.hibernate.Session db = getDB(); 352 368 353 369 this.log("Transmissionen - gelesen+1"); 354 d b.update("UPDATE transmissionen SET gelesen=gelesen+1 WHERE gelesen>=2");370 database.update("UPDATE transmissionen SET gelesen=gelesen+1 WHERE gelesen>=2"); 355 371 356 372 this.log("Loesche alte Transmissionen"); 357 d b.update("DELETE FROM transmissionen WHERE gelesen>=10");373 database.update("DELETE FROM transmissionen WHERE gelesen>=10"); 358 374 359 375 this.log("Erhoehe Inaktivitaet der Spieler"); 360 db.update("UPDATE users SET inakt=inakt+1 WHERE vaccount=0"); 376 db.createQuery("update User set inakt=inakt+1 where vaccount=0") 377 .executeUpdate(); 361 378 362 379 this.log("Erhoehe Tickzahl"); 363 d b.update("UPDATE config SET ticks=ticks+1");380 database.update("UPDATE config SET ticks=ticks+1"); 364 381 365 382 … … 372 389 373 390 this.log("Zaehle Timeout bei Umfragen runter"); 374 d b.update("UPDATE surveys SET timeout=timeout-1 WHERE timeout>0");391 database.update("UPDATE surveys SET timeout=timeout-1 WHERE timeout>0"); 375 392 376 393 this.log("Entsperre alle evt noch durch den Tick gesperrten Accounts");
