<%@ LANGUAGE = VBScript %><% Option Explicit %><% Dim INITIAL_WALL, INITIAL_GUN, INITIAL_BUILDER, INITIAL_SHOOTER, MAX_GUN, MAX_WALL INITIAL_WALL = 30 INITIAL_GUN = 1 INITIAL_BUILDER = 1 INITIAL_SHOOTER = 1 MAX_GUN = 50 MAX_WALL = 200 Response.CacheControl = "no-cache" Response.Expires = -1 Dim db, strPlayer, strBattle, strTitle, strOpponent, intAttack, strInstruction, d, dv, o, ov, op, UpdateStrength, strID strPlayer = Request.Cookies("player") strTitle = Request.Cookies("tower") strBattle = Request.QueryString("b") strOpponent = Request.QueryString("op") strInstruction = Request.QueryString("i") Set db = New Database Dim Destroyed Destroyed = False db.Read "SELECT ov FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" If Not db.rs.EOF Then If db.rs.Fields("ov").Value = 0 Then Destroyed = True End If db.Close If (Not Destroyed Or strInstruction = "i") And strInstruction <> "" And strInstruction = Left(LCase(strInstruction), 1) Then 'command is correctly formatted - ie. not an injection. db.Read "SELECT * FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" If db.rs.EOF Then db.Close d = INITIAL_WALL dv = INITIAL_BUILDER o = INITIAL_GUN ov = INITIAL_SHOOTER If strBattle = "" Then 'find a good battleground strBattle = 1 End If db.conn.execute "INSERT INTO p_castles (title, color, d, dv, o, ov, cookie, battle, kills, focus) VALUES ('" & Replace(strTitle, "'", "''") & "', " & Replace(getColor(strTitle), "'", "''") & ", " & Replace(d, "'", "''") & ", " & Replace(dv, "'", "''") & ", " & Replace(o, "'", "''") & ", " & Replace(ov, "'", "''") & ", '" & Replace(strPlayer, "'", "''") & "', " & Replace(strBattle, "'", "''") & ", 0, 0)" Else db.Close End If Dim intX, intTotal Select Case strInstruction Case "i" 'Initialize d = INITIAL_WALL dv = INITIAL_BUILDER o = INITIAL_GUN ov = INITIAL_SHOOTER If strBattle = "" Then 'find a good battleground strBattle = 1 End If db.conn.execute "UPDATE p_castles SET title = '" & Replace(strTitle, "'", "''") & "', color = " & Replace(getColor(strTitle), "'", "''") & ", d = " & Replace(d, "'", "''") & ", dv = " & Replace(dv, "'", "''") & ", o = " & Replace(o, "'", "''") & ", ov = " & Replace(ov, "'", "''") & ", battle = " & Replace(strBattle, "'", "''") & ", kills = 0, focus = 0 WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" db.Read "SELECT castle FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" strID = db.rs.Fields("castle") db.Close Case "o" 'Offensive Guy Upgrade db.conn.execute "UPDATE p_castles SET focus = 0, ov = (ov + 1) WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "p" 'Offensive Guy Upgrading db.conn.execute "UPDATE p_castles SET focus = 1 WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "d" 'Defensive Guy Upgrade db.conn.execute "UPDATE p_castles SET focus = 0, dv = (dv + 1) WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "e" 'Defensive Guy Upgrading db.conn.execute "UPDATE p_castles SET focus = 2 WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "g" 'Gun Upgrade db.Read "SELECT o, ov FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" intX = db.rs.Fields("o").Value + db.rs.Fields("ov").Value If intX > MAX_GUN Then intX = MAX_GUN db.Close db.conn.execute "UPDATE p_castles SET focus = 0, o = " & intX & " WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "h" 'Gun Upgrading db.conn.execute "UPDATE p_castles SET focus = 3 WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "w" 'Wall Upgrade db.Read "SELECT d, dv FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" intX = db.rs.Fields("d").Value + db.rs.Fields("dv").Value If intX > MAX_WALL Then intX = MAX_WALL db.Close db.conn.execute "UPDATE p_castles SET focus = 0, d = " & intX & " WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "x" 'Wall Upgrading db.conn.execute "UPDATE p_castles SET focus = 4 WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" Case "b" 'Begin Attack db.conn.execute "UPDATE p_castles SET focus = 5, op = " & Replace(strOpponent, "'", "''") & " WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" ' db.rs.Fields("op").Value = strOpponent ' db.rs.Update Case "a" 'Finish Attack db.conn.execute "UPDATE p_castles SET focus = 6 WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" db.Read "SELECT o, op FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" intAttack = db.rs.Fields("o").Value strOpponent = db.rs.Fields("op").Value db.Close db.Read "SELECT d, dv, o, ov FROM p_castles WHERE castle = " & strOpponent & " LIMIT 1" d = db.rs.Fields("d").Value dv = db.rs.Fields("dv").Value o = db.rs.Fields("o").Value ov = db.rs.Fields("ov").Value db.Close intX = d - intAttack If intX < 0 Then intAttack = intAttack - d d = 0 intX = o - intAttack If intX < 0 Then intAttack = intAttack - o o = 0 intX = ov - intAttack If intX < 0 Then intAttack = intAttack - ov ov = 0 intX = dv - intAttack If intX < 0 Then intAttack = intAttack - dv dv = 0 Else dv = intX End If Else ov = intX End If Else o = intX End If Else d = intX End If db.conn.execute "UPDATE p_castles SET d = " & d & ", o = " & o & ", ov = " & ov & ", dv = " & dv & " WHERE castle = " & strOpponent & " LIMIT 1" ' db.rs.Update ' db.Close ' db.Open "SELECT * FROM p_castles WHERE cookie = '" & Replace(strPlayer, "'", "''") & "' LIMIT 1" ' db.rs.Fields("op").Value = 0 ' db.rs.Update End Select End If 'Instruction performed 'Now for the output: If strBattle = "" Then 'find a good battleground strBattle = 1 End If Dim str If strInstruction = "i" Then Response.Write(strID) Else If Destroyed Then Response.Write("You have been defeated!") Else db.Read "SELECT castle, title, color, d, dv, o, ov, op, cookie, battle, age, kills, focus FROM p_castles WHERE battle = " & Replace(strBattle, "'", "''") & " AND dv > 0 ORDER BY cookie" If Not db.rs.EOF Then str = db.rs.GetString(, , "','", "'],['", "") Else str = "'],['" End If db.Close Response.Write("[['" & Left(str, Len(str) - 3) & "]") End If End If Set db = Nothing Function getColor(str) getColor = Asc(Left(str, 1)) End Function %>