public Raid( double distance, int ticksToHit, Town town1, Town town2, boolean Genocide, boolean Bomb, int support, boolean invade, String name, boolean debris, ArrayList<AttackUnit> au, int digAmt) { // Can't do an infinite number of arguments here so need to add manually. // holds distance and ticksToHit in this object. this.setInvade(invade); this.setSupport(support); this.setDebris(debris); this.digAmt = digAmt; this.setName(name); this.au = au; this.setDistance(distance); this.setTicksToHit(ticksToHit); if (distance == 0) distance = 1; God = town1.getPlayer().God; this.setBomb(Bomb); this.setTown2(town2); this.setTown1(town1); setRaidOver(false); this.setTotalTicks(ticksToHit); this.setGenocide(Genocide); if (Genocide) setAllClear( false); // Note you need to watch in loaded raids, that raidOver and allClear need to be // set manually. // player1 hits player2's town2, only need town2 to access units. UberStatement stmt; try { con = town1.getPlayer().God.con; stmt = con.createStatement(); // First things first. We update the player table. boolean transacted = false; while (!transacted) { try { stmt.execute( "start transaction;"); // it's logged in, starts transaction so data problems won't // happen. // let's add this raid and therefore get the rid out of it. stmt.executeUpdate( "insert into raid (tid1, tid2, distance, ticksToHit, genocide, raidOver,allClear,m,t,mm,f,totalTicks,Bomb,support,invade,name,debris,digAmt) values (" + town1.townID + "," + town2.townID + "," + distance + "," + ticksToHit + "," + Genocide + "," + false + "," + false + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + ticksToHit + "," + Bomb + "," + support + "," + invade + ",\"" + name + "\"," + debris + "," + digAmt + ");"); stmt.execute("commit;"); Thread.currentThread().sleep(10); ResultSet ridstuff = stmt.executeQuery( "select rid from raid where tid1 = " + town1.townID + " and raidOver = false"); /* *Okay, search out all raids on the db for this town, and compare them to the raid server that the town has. There should be an rid *corresponding to each raid on there, and one that isn't. This one is our rid. *Now, if the user is running concurrent threads and they both call to this to add the raid at the same time, then there will be two *separate raidIDs on there. Still something of a problem, but we have to acknowledge the quickness of this maneuver - this thing will *literally be lightning quick. It'll snatch up that rid and add this one to the server without a hesitation. *if there is a problem, we can always assign a huge random number tempid to it, and use that as an extra comparison. If the user *does do two things at once, two raids, then I have to ask - what is the problem with switching the rids up? You see, if he does manage *to do it on the same town at the same time within a time frame that would allow both to be unaccounted for at the same time, then as soon *as the rids are switched, the player object would update them both with correct values from us. There we go. It happens so quickly. */ while (ridstuff.next()) { int j = 0; ArrayList<Raid> attackServer = town1.attackServer(); while (j < attackServer.size()) { if (attackServer.get(j).raidID == ridstuff.getInt(1)) break; j++; } if (j == attackServer.size()) break; // means we found no raid accompanying this raidID. } raidID = (ridstuff.getInt(1)); // town1.attackServer.add(this); // <---- THIS NEEDS TO BE RETURNED TO NORMAL IF YOU GO // BACK TO MEMORYLOADING! // System.out.println("I put on " +raidID); town1.attackServer().add(this); // even if this error happens, raid still works... ridstuff.close(); stmt.execute("commit;"); /* int timesTried = 0; ArrayList<Raid> a = town1.attackServer(); while(a.size()<=0&×Tried<10) { Thread.currentThread().sleep(10); a= town1.attackServer(); timesTried++; } raidID=a.get(a.size()-1).raidID;*/ stmt.close(); transacted = true; } catch (MySQLTransactionRollbackException exc) { } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // need connection for attackunit adds! } catch (SQLException exc) { exc.printStackTrace(); } }
public Raid( int raidID, double distance, int ticksToHit, Town town1, Town town2, boolean Genocide, boolean allClear, int metal, int timber, int manmat, int food, boolean raidOver, ArrayList<AttackUnit> au, boolean Bomb, boolean invade, int totalTicks, String name, int genoRounds, boolean debris, int digAmt) { // This constructor does not use the support integer because it is rarely used compared to other // things // and so to save space that is exported as an extra usable method. It is only necessary // when creating raids. // this constructor is for when a raid is being loaded into memory. if (distance == 0) distance = 1; this.digAmt = digAmt; this.setDebris(debris); this.distance = distance; this.ticksToHit = ticksToHit; this.town1 = town1; this.town2 = town2; this.Genocide = Genocide; this.allClear = allClear; this.metal = metal; this.timber = timber; this.manmat = manmat; this.food = food; this.raidOver = raidOver; this.au = au; this.Bomb = Bomb; this.invade = invade; this.totalTicks = totalTicks; this.name = name; this.genoRounds = genoRounds; UberStatement stmt; try { con = town1.getPlayer().God.con; God = town1.getPlayer().God; stmt = con.createStatement(); // First things first. We update the player table. boolean transacted = false; while (!transacted) { try { stmt.execute( "start transaction;"); // it's logged in, starts transaction so data problems won't // happen. // let's add this raid and therefore get the rid out of it. stmt.executeUpdate( "insert into raid (tid1, tid2, distance, ticksToHit, genocide, raidOver,allClear,m,t,mm,f,totalTicks,Bomb,invade,name,genoRounds,digAmt) values (" + town1.townID + "," + town2.townID + "," + distance + "," + ticksToHit + "," + Genocide + "," + false + "," + false + "," + 0 + "," + 0 + "," + 0 + "," + 0 + "," + ticksToHit + "," + Bomb + "," + invade + ",\"" + name + "\"," + genoRounds + "," + digAmt + ");"); stmt.execute("commit;"); Thread.currentThread().sleep(10); ResultSet ridstuff = stmt.executeQuery( "select rid from raid where tid1 = " + town1.townID + " and raidOver = false"); while (ridstuff.next()) { int j = 0; ArrayList<Raid> attackServer = town1.attackServer(); while (j < attackServer.size()) { if (attackServer.get(j).raidID == ridstuff.getInt(1)) break; j++; } if (j == attackServer.size()) break; // means we found no raid accompanying this raidID. } raidID = (ridstuff.getInt(1)); // town1.attackServer.add(this); // <---- THIS NEEDS TO BE RETURNED TO NORMAL IF YOU GO // BACK TO MEMORYLOADING! // System.out.println("I put on " +raidID); ridstuff.close(); /* Thread.currentThread().sleep(100); int timesTried = 0; ArrayList<Raid> a = town1.attackServer(); while(a.size()<=0&×Tried<1000) { // we wait longer for raids...f*****g a raid up is really bad...REALLY. // because we add shit to it after it is made! Of course, could f**k up oppositely, and take a raid already // on there and add shit to it, either way, bad for biz. So we wait 100ms before we even try. Thread.currentThread().sleep(10); a= town1.attackServer(); timesTried++; } raidID=a.get(a.size()-1).raidID;*/ int i = 0; while (i < au.size()) { add(au.get(i)); i++; } stmt.close(); transacted = true; } catch (MySQLTransactionRollbackException exc) { } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // need connection for attackunit adds! } catch (SQLException exc) { exc.printStackTrace(); } }