public void add(AttackUnit j) { // THIS IS ONLY FOR DB USAGE... // getAu().add(j); UberStatement stmt; try { 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. if (j.getSlot() < 6) { stmt.executeUpdate( "update raid set au" + (j.getSlot() + 1) + " = " + j.getSize() + " where rid = " + raidID + ";"); } else { stmt.executeUpdate( "insert into raidSupportAU (rid,tid,tidslot,size) values (" + raidID + "," + getTown1().townID + "," + j.getSlot() + "," + j.getSize() + ");"); // don't need original slot, need // current town slot for remembering! } stmt.execute("commit;"); stmt.close(); transacted = true; } catch (MySQLTransactionRollbackException exc) { System.out.println(raidID + " is having trouble adding units."); } } } catch (SQLException exc) { exc.printStackTrace(); } }
public void deleteMe() { // Although raids are not removed from the sql server, their supporting au should be. They are // merely placeholders // and will either survive or goto zero, besides, the statreports exist to tell the true story. // By placeholders I mean they are like extra au fields for the raid, the actual // data is held on the supportAU table. try { int k = 6; UberStatement stmt = con.createStatement(); ArrayList<AttackUnit> au = getAu(); // stmt.executeUpdate("update raid set ticksToHit=-1 where rid = " + raidID); setTicksToHit(-1); save(); // save the current state right before deletion. while (k < au.size()) { stmt.executeUpdate( "delete from raidSupportAU where tid = " + getTown1().townID + " and rid = " + raidID + " and tidslot = " + au.get(k).getSlot() + ";"); k++; } stmt.close(); getTown1().attackServer().remove(this); // and we remove it from memory.... } catch (SQLException exc) { exc.printStackTrace(); } }
public void setMemSize(int index, int size) { if (index < 6) setInt("au" + (index + 1), size); else { try { UberStatement stmt = con.createStatement(); AttackUnit a = getAu().get(index); stmt.executeUpdate( "update raidSupportAU set size = " + size + " where tidslot = " + a.getSlot() + " and rid = " + raidID + " and tid = " + getTown1().townID); stmt.close(); } catch (SQLException exc) { exc.printStackTrace(); System.out.println("Your shit is a-okay."); } } }
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(); } }
public synchronized void save() { try { UberStatement stmt = con.createStatement(); ArrayList<AttackUnit> au = getAu(); if (getTown1().townID == 3569) System.out.println("I am raid " + raidID); String update = ""; try { update = "update raid set distance = " + distance + ", ticksToHit = " + ticksToHit + ", genocide = " + Genocide + ", raidOver = " + raidOver + ", allClear = " + allClear + ", m = " + metal + ", t = " + timber + ", mm = " + manmat + ", f = " + food + ", au1 = " + au.get(0).getSize() + ", au2 = " + au.get(1).getSize() + ", au3 = " + au.get(2).getSize() + ", au4 = " + au.get(3).getSize() + ", au5 = " + au.get(4).getSize() + ", au6 = " + au.get(5).getSize() + ", bomb = " + Bomb + ", bombtarget = " + bombTarget + ", support = " + support + ", scout = " + scout + ", invade = " + invade + ", resupplyID = " + resupplyID + ", totalTicks = " + totalTicks + " where rid = " + raidID + ";"; } catch (IndexOutOfBoundsException exc) { exc.printStackTrace(); System.out.println("Found"); } stmt.executeUpdate(update); int k = 6; while (k < au.size()) { stmt.executeUpdate( "update raidSupportAU set size = " + au.get(k).getSize() + " where tid = " + town1.townID + " and rid = " + raidID + " and tidslot = " + au.get(k).getSlot() + ";"); k++; } stmt.close(); // either being added back to town or was completely wiped out, either way, should be removed // from memory. } catch (SQLException exc) { exc.printStackTrace(); } }