Changeset 6676c578fa82a76a889fd27f701f075fab962669
- Timestamp:
- 05/22/08 18:11:25 (3 months ago)
- git-parent:
- Files:
-
- db/tables/forschungen.sql (modified) (1 diff)
- db/tables/userresearch.sql (added)
- db/updates.xml (modified) (1 diff)
- src/net/driftingsouls/ds2/server/entities/User.java (modified) (7 diffs)
- src/net/driftingsouls/ds2/server/entities/UserResearch.java (added)
- src/net/driftingsouls/ds2/server/framework/BasicUser.java (modified) (2 diffs)
- src/net/driftingsouls/ds2/server/modules/PortalController.java (modified) (3 diffs)
- src/net/driftingsouls/ds2/server/modules/SchiffInfoController.java (modified) (3 diffs)
- src/net/driftingsouls/ds2/server/modules/StatsController.java (modified) (3 diffs)
- src/net/driftingsouls/ds2/server/modules/admin/PlayerDelete.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
db/tables/forschungen.sql
r425acaa r6676c57 14 14 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 15 15 16 set sql_mode = NO_AUTO_VALUE_ON_ZERO; 17 18 INSERT INTO `forschungen` (`id`, `name`, `req1`, `req2`, `req3`, `time`, `costs`, `descrip`, `race`, `visibility`, `flags`) VALUES (-1, '(nicht erfuellbar)', -1, -1, -1, 0, '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,', '', 0, 2, ''); 19 INSERT INTO `forschungen` (`id`, `name`, `req1`, `req2`, `req3`, `time`, `costs`, `descrip`, `race`, `visibility`, `flags`) VALUES (0, '(immer erfuellt)', -1, -1, -1, 0, '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,', '', 0, 2, ''); 16 20 INSERT INTO `forschungen` (`id`, `name`, `req1`, `req2`, `req3`, `time`, `costs`, `descrip`, `race`, `visibility`, `flags`) VALUES (1, 'Fusionsreaktor-Konstruktion', 2, 0, 0, 3, '0,0,0,0,0,0,0,0,80,0,0,0,0,0,0,0,0,0,', '', 0, 1, ''); 17 21 INSERT INTO `forschungen` (`id`, `name`, `req1`, `req2`, `req3`, `time`, `costs`, `descrip`, `race`, `visibility`, `flags`) VALUES (2, 'Werftsysteme', 3, 6, 0, 3, '0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,', '', 0, 1, ''); db/updates.xml
rc09e0ad r6676c57 504 504 alter table users add blocked tinyint(1) unsigned not null default '0'; 505 505 ]]></update> 506 <update type="structure" datum="2008-05-18"><![CDATA[ 507 CREATE TABLE `userresearch` ( 508 `id` int(11) unsigned NOT NULL auto_increment, 509 `owner` int(11) NOT NULL, 510 `research` int(11) NOT NULL, 511 PRIMARY KEY (`id`), 512 UNIQUE (`owner`,`research`) 513 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Forschungen der Spieler'; 514 ALTER TABLE userresearch ADD CONSTRAINT userresearch_fk_forschungen FOREIGN KEY (research) REFERENCES forschungen(id); 515 ]]></update> 516 <update type="data" datum="2008-05-18"><![CDATA[ 517 set sql_mode = NO_AUTO_VALUE_ON_ZERO; 518 519 INSERT INTO `forschungen` (`id`, `name`, `req1`, `req2`, `req3`, `time`, `costs`, `descrip`, `race`, `visibility`, `flags`) VALUES (-1, '(nicht erfuellbar)', -1, -1, -1, 0, '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,', '', 0, 2, ''); 520 INSERT INTO `forschungen` (`id`, `name`, `req1`, `req2`, `req3`, `time`, `costs`, `descrip`, `race`, `visibility`, `flags`) VALUES (0, '(immer erfuellt)', -1, -1, -1, 0, '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,', '', 0, 2, ''); 521 522 DELIMITER // 523 DROP PROCEDURE IF EXISTS `convert_f`// 524 DROP PROCEDURE IF EXISTS `convert_f_user`// 525 CREATE PROCEDURE convert_f_user(uid INT) 526 BEGIN 527 DECLARE rid INT DEFAULT 0; 528 DECLARE selectQuery CHAR(255); 529 DECLARE rValue INT DEFAULT 0; 530 DECLARE rCount INT DEFAULT 0; 531 532 SET rid=0; 533 WHILE rid <= 100 DO 534 SELECT count(*) INTO rCount FROM forschungen WHERE id=rid; 535 IF rCount > 0 THEN 536 SET selectQuery = CONCAT("SELECT r",rid," into @rValue from user_f where id=",uid); 537 SET @qry = selectQuery; 538 539 PREPARE stmt FROM @qry; 540 EXECUTE stmt; 541 DEALLOCATE PREPARE stmt; 542 543 IF @rValue > 0 THEN 544 INSERT INTO userresearch (owner,research) VALUES (uid,rid); 545 END IF; 546 547 END IF; 548 SET rid=rid+1; 549 END WHILE; 550 END; 551 552 CREATE PROCEDURE convert_f() 553 BEGIN 554 DECLARE done,uid INT DEFAULT 0; 555 DECLARE cur1 CURSOR FOR SELECT id FROM users; 556 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; 557 558 OPEN cur1; 559 REPEAT 560 FETCH cur1 INTO uid; 561 CALL convert_f_user(uid); 562 UNTIL done END REPEAT; 563 CLOSE cur1; 564 END; 565 // 566 DELIMITER ; 567 568 CALL convert_f(); 569 DROP PROCEDURE `convert_f`; 570 DROP PROCEDURE `convert_f_user`; 571 ]]></update> 506 572 </updates> src/net/driftingsouls/ds2/server/entities/User.java
rc09e0ad r6676c57 32 32 import javax.persistence.Transient; 33 33 34 import net.driftingsouls.ds2.server.cargo.Cargo; 35 import net.driftingsouls.ds2.server.comm.Ordner; 34 36 import net.driftingsouls.ds2.server.framework.BasicUser; 35 37 import net.driftingsouls.ds2.server.framework.Common; … … 38 40 import net.driftingsouls.ds2.server.framework.ContextMap; 39 41 import net.driftingsouls.ds2.server.framework.Loggable; 40 import net.driftingsouls.ds2.server.framework.db.SQLResultRow;41 42 import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 42 43 import net.driftingsouls.ds2.server.werften.BaseWerft; … … 210 211 211 212 /** 213 * Legt einen neuen Spieler an. 214 * 215 * @param name Loginname des Spielers. 216 * @param password Passwort - md5-verschluesselt. 217 * @param race Rasse des Spielers. 218 * @param history Bisherige Geschichte des Spielers. 219 * @param cargo Ressourcen im Spielercargo. 220 * @param email E-Mailadresse des Spielers. 221 */ 222 public User(String name, String password, int race, String history, Cargo cargo, String email) { 223 super(); 224 context = ContextMap.getContext(); 225 org.hibernate.Session db = context.getDB(); 226 setPassword(password); 227 setName("Kolonist"); 228 this.race = race; 229 this.history = history; 230 setCargo(cargo.save()); 231 setEmail(email); 232 setUn(name); 233 setFlag(User.FLAG_NOOB); 234 setNahrungsStat("0"); 235 setSignup((int)Common.time()); 236 setImagePath(BasicUser.getDefaultImagePath()); 237 setInactivity(0); 238 setMedals(""); 239 setRang(Byte.valueOf("0")); 240 setKonto(BigInteger.valueOf(0)); 241 setLoginFailedCount(0); 242 setAccesslevel(0); 243 setNpcPunkte(0); 244 setNickname("Kolonist"); 245 setPlainname("Kolonist"); 246 setGtuDropZone(2); 247 setNpcOrderLocation(""); 248 setDisabled(false); 249 setVacationCount(0); 250 setWait4VacationCount(0); 251 setLostBattles(Short.valueOf("0")); 252 setLostShips(0); 253 setWonBattles(Short.valueOf("0")); 254 setDestroyedShips(0); 255 int newUserId = (Integer)db.createQuery("SELECT max(id) from User").uniqueResult(); 256 newUserId++; 257 setId(newUserId); 258 this.knownItems = ""; 259 db.persist(this); 260 Ordner trash = Ordner.createNewOrdner("Papierkorb", Ordner.getOrdnerByID(0, this), this); 261 trash.setFlags(Ordner.FLAG_TRASH); 262 addResearch(0); 263 } 264 265 /** 212 266 * Macht alle geladenen Benutzereigenschaften dem Templateengine bekannt. 213 267 * Die daraus resultierenden Template-Variablen haben die Form Prefix+"."+Datenbankname. … … 604 658 } 605 659 606 @Transient607 private SQLResultRow research = null;608 660 private int vaccount; 609 661 private int wait4vac; 610 662 611 663 /** 612 * Gibt den zum Spieler gehoerenden <code>user_f</code>-Eintrag als SQL-Ergebniszeile613 * zurueck614 * @return Der <code>user_f</code>-Eintrag615 */616 public SQLResultRow getResearchedList() {617 if( research == null ) {618 research = context.getDatabase().first("SELECT * FROM user_f WHERE id='",this.getId(),"'");619 if( research.isEmpty() ) {620 throw new RuntimeException("Spieler "+this.getId()+" verfuegt ueber keine Forschungstabelle");621 }622 }623 return research;624 }625 626 /**627 664 * Prueft, ob die angegebene Forschung durch den Benutzer erforscht wurde 628 665 * … … 631 668 */ 632 669 public boolean hasResearched( int researchID ) { 633 // Forschungs-ID -1 ist per Definition nicht erforschbar - also immer false zurueckgeben. 634 if( researchID == -1 ) { 635 return false; 636 } 637 if( research == null ) { 638 research = context.getDatabase().first("SELECT * FROM user_f WHERE id='",this.getId(),"'"); 639 if( research.isEmpty() ) { 640 throw new RuntimeException("Spieler "+this.getId()+" verfuegt ueber keine Forschungstabelle"); 641 } 642 } 643 644 return research.getBoolean("r"+researchID); 670 return getUserResearch(Forschung.getInstance(researchID)) != null; 645 671 } 646 672 … … 650 676 */ 651 677 public void addResearch( int researchID ) { 652 if( !hasResearched( researchID ) ) { 653 research.put("r"+researchID, true); 654 655 context.getDatabase().update("UPDATE user_f SET r",researchID,"='1' WHERE id='",this.getId(),"'"); 656 } 678 org.hibernate.Session db = context.getDB(); 679 db.persist(new UserResearch(this, Forschung.getInstance(researchID))); 657 680 } 658 681 … … 1023 1046 this.blocked = blocked; 1024 1047 } 1048 1049 /** 1050 * Gibt zur angegebenen Forschung die Forschungsdaten des Benutzers zurueck. 1051 * Falls der Benutzer die Forschung noch nicht hat wird <code>null</code> zurueckgegeben. 1052 * @param research Die Forschung 1053 * @return Die Forschungsdaten oder <code>null</code> 1054 */ 1055 public UserResearch getUserResearch(Forschung research) { 1056 if(research == null) { 1057 return null; 1058 } 1059 org.hibernate.Session db = context.getDB(); 1060 return (UserResearch) db.createQuery("from UserResearch where owner=? AND research=?").setInteger(0, this.getId()).setInteger(1, research.getID()).uniqueResult(); 1061 } 1025 1062 } src/net/driftingsouls/ds2/server/framework/BasicUser.java
rc09e0ad r6676c57 451 451 } 452 452 453 protected void setId(int id) 454 { 455 this.id = id; 456 } 457 453 458 /** 454 459 * (De)aktiviert den Account. … … 466 471 return this.version; 467 472 } 473 474 /** 475 * Setzt die Email-Adresse des Spielers 476 * @param email Die Email 477 */ 478 protected void setEmail(String email) { 479 this.email = email; 480 } 481 482 /** 483 * Setzt den Plaintext-Namen des Spielers 484 * @param plainname Der Name 485 */ 486 protected void setPlainname(String plainname) { 487 this.plainname = plainname; 488 } 489 490 /** 491 * Setzt den Zeitpunkt, zu dem sich der User registriert hat 492 * in Sekunden seit dem 1.1.1970 493 * @param signup Die Timestamp 494 */ 495 protected void setSignup(int signup) { 496 this.signup = signup; 497 } 498 499 /** 500 * Setzt den Loginnamen des Users 501 * @param un Der Loginname 502 */ 503 protected void setUn(String un) { 504 this.un = un; 505 } 506 507 /** 508 * Setzt den Zugriffslevel den Users auf Adminfunktionen 509 * @param accesslevel Der Level 510 */ 511 protected void setAccesslevel(int accesslevel) { 512 this.accesslevel = accesslevel; 513 } 468 514 } src/net/driftingsouls/ds2/server/modules/PortalController.java
rc09e0ad r6676c57 33 33 import net.driftingsouls.ds2.server.cargo.Cargo; 34 34 import net.driftingsouls.ds2.server.cargo.Resources; 35 import net.driftingsouls.ds2.server.comm.Ordner;36 35 import net.driftingsouls.ds2.server.comm.PM; 37 36 import net.driftingsouls.ds2.server.config.Rasse; … … 524 523 cargo.addResource( Resources.NAHRUNG, 100000 ); 525 524 526 db.tUpdate(1,"INSERT INTO users (id,un,passwort,race,signup,history,email,cargo,flags,nstat) " , 527 "VALUES " , 528 "('",newid,"','",username,"','",enc_pw,"','",race,"','",Common.time(),"','",history,"','",email,"','",cargo.save(),"','",User.FLAG_NOOB,"','0')"); 529 530 // Standard-Ordner erstellen 531 db.tUpdate(1, "INSERT INTO ordner SET name='Papierkorb',playerid='",newid,"',flags='",Ordner.FLAG_TRASH,"',parent=0"); 532 533 db.tUpdate(1, "INSERT INTO user_f (id) VALUES ('",newid,"')"); 525 User newuser = new User(username, enc_pw, race, history, cargo, email); 534 526 535 527 // Schiffe erstellen … … 578 570 } 579 571 580 User newuser = (User)getDB().get(User.class, newid);572 //User newuser = (User)getDB().get(User.class, newid); 581 573 582 574 base.setEnergy(base.getMaxEnergy()); src/net/driftingsouls/ds2/server/modules/SchiffInfoController.java
r7a648c6 r6676c57 35 35 import net.driftingsouls.ds2.server.entities.OrderShip; 36 36 import net.driftingsouls.ds2.server.entities.User; 37 import net.driftingsouls.ds2.server.entities.UserResearch; 37 38 import net.driftingsouls.ds2.server.framework.Common; 38 39 import net.driftingsouls.ds2.server.framework.Context; 39 import net.driftingsouls.ds2.server.framework.db.Database;40 import net.driftingsouls.ds2.server.framework.db.SQLResultRow;41 40 import net.driftingsouls.ds2.server.framework.pipeline.generators.Action; 42 41 import net.driftingsouls.ds2.server.framework.pipeline.generators.ActionType; … … 130 129 131 130 private void outPrerequisites() { 132 Database db = getDatabase();133 131 TemplateEngine t = getTemplateEngine(); 134 132 … … 136 134 for( int i=1; i <= 3; i++ ) { 137 135 if( shipBuildData.getRes(i) != 0 ) { 138 SQLResultRow dat = db.first("SELECT f.name, uf.r",shipBuildData.getRes(i)," AS research " + 139 "FROM forschungen f JOIN user_f uf " + 140 "WHERE f.id=",shipBuildData.getRes(i)," AND uf.id=",getUser().getId()); 141 String cssClass = "error"; 142 if( !dat.isEmpty() && dat.getBoolean("research") ) { 136 User user = (User)getUser(); 137 Forschung research = Forschung.getInstance(shipBuildData.getRes(i)); 138 UserResearch userResearch = user.getUserResearch(research); 139 String cssClass = "error"; 140 //Has the user this research? 141 if(userResearch != null) 142 { 143 143 cssClass = "ok"; 144 } 144 } 145 145 146 146 t.setVar( "shiptype.tr"+i, shipBuildData.getRes(i), 147 "shiptype.tr"+i+".name" , Common._title( dat.getString("name")),147 "shiptype.tr"+i+".name" , Common._title(research.getName()), 148 148 "shiptype.tr"+i+".status", cssClass ); 149 149 } src/net/driftingsouls/ds2/server/modules/StatsController.java
r327b751 r6676c57 25 25 import java.util.Map; 26 26 27 import net.driftingsouls.ds2.server.cargo.Cargo;28 import net.driftingsouls.ds2.server.cargo.Resources;29 import net.driftingsouls.ds2.server.entities.Forschung;30 27 import net.driftingsouls.ds2.server.framework.Common; 31 28 import net.driftingsouls.ds2.server.framework.Context; … … 224 221 } 225 222 226 ///////////////////////////////////////////227 228 if( (mystat.stat.getRequiredData() & Statistic.DATA_RESEARCH) != 0 ) {229 generateResearchData(db, mystat, maxid);230 }231 232 ///////////////////////////////////////////233 223 234 224 StringBuffer echo = getContext().getResponse().getContent(); … … 245 235 246 236 echo.append(Common.tableEnd()); 247 }248 249 private void generateResearchData(Database db, StatEntry mystat, int maxid) {250 db.update("CREATE TEMPORARY TABLE IF NOT EXISTS tmpres ( ",251 "id int(11) NOT NULL auto_increment, ",252 "res int(11) NOT NULL default '0', ",253 "sili int(11) NOT NULL default '0', ",254 "iso int(11) NOT NULL default '0', ",255 "PRIMARY KEY (id), ",256 "KEY res(res), ",257 "KEY sili(sili), ",258 "KEY iso(iso) ",259 ");");260 261 db.update("DELETE FROM tmpres");262 263 Map<Integer,Integer> res = new HashMap<Integer,Integer>();264 Map<Integer,Long> ress = new HashMap<Integer,Long>();265 Map<Integer,Long> resi = new HashMap<Integer,Long>();266 267 SQLQuery userf = null;268 if( !mystat.stat.generateAllyData() ) {269 userf = db.query("SELECT *,id theid FROM user_f WHERE id>",MIN_USER_ID);270 271 }272 else {273 userf = db.query("SELECT uf.*,u.ally theid " +274 "FROM user_f uf JOIN users u ON uf.id=u.id " +275 "WHERE uf.id>",MIN_USER_ID," AND u.ally IS NOT NULL");276 }277 278 while( userf.next() ) {279 int i = userf.getInt("theid");280 for( int a=1; a < MAX_RESID; a++ ) {281 if( userf.getInt("r"+a) == 1 ) {282 if( !res.containsKey(i) ) {283 res.put(i, 0);284 ress.put(i, 0l);285 resi.put(i, 0l);286 }287 res.put(i, res.get(i)+1);288 289 Forschung forschung = Forschung.getInstance(a);290 if( forschung != null ) {291 Cargo cargo = forschung.getCosts();292 ress.put( i, ress.get(i) + cargo.getResourceCount( Resources.SILIZIUM ) );293 resi.put(i, resi.get(i) + cargo.getResourceCount( Resources.ISOCHIPS ) );294 }295 }296 }297 }298 userf.free();299 300 List<String> insertstring = new ArrayList<String>();301 for( int i=1; i <= maxid; i++ ) {302 if( res.containsKey(i) ) {303 insertstring.add("("+i+","+res.get(i)+","+ress.get(i)+","+resi.get(i)+")");304 }305 }306 307 if( insertstring.size() > 0 ) {308 db.update("INSERT INTO tmpres VALUES "+Common.implode(",", insertstring));309 }310 237 } 311 238 src/net/driftingsouls/ds2/server/modules/admin/PlayerDelete.java
r16c4457 r6676c57 178 178 179 179 echo.append("Entferne user-forschungen...<br />\n"); 180 d atabase.update("DELETE FROM user_f WHERE id="+userid);180 db.createQuery("delete from UserResearch where owner=?").setInteger(0, userid).executeUpdate(); 181 181 182 182 //Schiffe
