%@ Language="Jscript" %>
<%
var touserid = "";
var toaddress = "";
var toname = "";
var tempuser = false;
if (Request.Form("submit") == "Send changes to opponent")
{
var messagetypeid = 5;
var user1id = String(Request.Form("user1"));
var user2id = String(Request.Form("user2"));
var rs = Server.CreateObject("adodb.recordset");
var sql = "select * from game where id = " + Request.QueryString("gameid");
rs.open(sql, conn, 0, 3);
rs.Movefirst();
}
else
{
var user1id = Session("userId");
//get the opponent id, but if he's not registered, do that first...
if (String(Request.Form("opponent")) != "undefined")
var user2id = Number(Request.Form("opponent"));
else
{
var opponentemail = String(Request.Form("email"));
var sql = "SELECT * FROM [user] where email = '" + opponentemail + "'";
var rs = Server.CreateObject("adodb.recordset");
rs.Open(sql, conn, 0, 3);
if (rs.eof || rs.bof)
{
tempuser = true;
//create a new provisional user
rs.AddNew();
rs("email") = opponentemail;
rs.Update();
var user2id = String(rs("id"));
rs("username") = "temp" + user2id;
rs("rating") = 1200;
rs("regdate") = getDate();
//create temp password
var f = new Date();
var password = String(f.getMilliseconds());
rs("pwd") = password;
rs.Update();
}
else
user2id = String(rs("id"));
}
var messagetypeid = 4;
var rs = Server.CreateObject("adodb.recordset");
var sql = "select * from game";
rs.open(sql, conn, 0, 3);
rs.AddNew();
}
Response.write("
Messagetypeid: " + messagetypeid + "
");
var user1citycount = String(Request.Form("user1citycount"));
if (user1citycount == "null")
user1citycount = "0";
var user2citycount = String(Request.Form("user2citycount"));
if (user2citycount == "null")
user2citycount = "0";
var mapwidth = String(Request.Form("width"));
var mapheight = String(Request.Form("height"));
var maptypeid = String(Request.Form("maptype"));
var endcondition = String(Request.Form("endcondition"));
var duration = String(Request.Form("duration"));
var gameversionid = String(Request.Form("gameversion"));
var gametype1id = String(Request.Form("gametype1"));
var gametype2id = String(Request.Form("gametype2"));
var description = String(Request.Form("description"));
var rated = String(Request.Form("rated"));
if (rated == "on")
rated = 1;
else
rated = 0;
rs("createtime") = getDate();
rs("completetime") = getDate();
rs("user1id") = Number(user1id);
rs("user2id") = user2id;
rs("user1citycount") = user1citycount;
rs("user2citycount") = user2citycount;
rs("mapwidth") = mapwidth;
rs("mapheight") = mapheight;
rs("maptypeid") = maptypeid;
switch (endcondition)
{
case "1":
rs("winnerid") = user1id;
break;
case "2":
rs("winnerid") = "0";
break;
case "3":
rs("winnerid") = user2id;
break;
}
rs("duration") = duration;
rs("gameversionid") = gameversionid;
rs("gametype1id") = gametype1id;
rs("gametype2id") = gametype2id;
if (description.length > 0)
rs("description") = description;
rs("gamestatusid") = 3;
rs("rated") = rated;
rs.Update();
var newid = rs("id");
sql = "insert into gamenegotiation (userid, messageid, [timestamp], gameid) values (";
sql += Session("userId") + ", ";
sql += messagetypeid + ", ";
sql += "'" + getDate() + "', ";
sql += newid;
sql += ")";
conn.Execute(sql);
//send email to user
if (Session("userid") == user1id)
touserid = user2id;
else
touserid = user1id;
var rs2 = Server.CreateObject("adodb.recordset");
sql = "select email, username from [user] where id = " + touserid;
rs2.Open(sql, conn);
toaddress = String(rs2("email"));
toname = String(rs2("username"));
var title = "";
var body = "";
if (!tempuser)
{
if (messagetypeid == 4)
{
title = "Game result reported!";
body = "Hi " + toname + "\n\n";
body += "Your opponent has reported the result of a game you were playing.\n";
body += "Please review the result at the Empire Deluxe Ladder in order to give your accept.\n";
body += "\nThe Empire Deluxe Corner\n";
body += "www.givoni.com/empire/";
sendEmail(toaddress, title, body);
}
else
{
title = "Game result changed!";
body = "Hi " + toname + "\n\n";
body += "Your opponent has changed the result of a game you were playing.\n";
body += "Please review the changes at the Empire Deluxe Ladder in order to give your accept.\n";
body += "\nThe Empire Deluxe Ladder\n";
body += "www.givoni.com/empire/";
sendEmail(toaddress, title, body);
}
}
else
{
//Send the welcome email to the new user
title = "Empire Deluxe game report!";
body = "Hi,\n\n";
body += "Your opponent in an Empire Deluxe game you recently have played, has reported the result to The Empire Deluxe Ladder.\n";
body += "He/she gave your email address, and you have therefore been registered as a provisional player at the website.\n";
body += "If you wish to accept the game result, and become a member of the website, please review the result at this page in order to give your accept.\n";
body += "\nYour provisional login information is:\n";
body += "Username: " + "temp" + user2id + "\n";
body += "Password: " + password + "\n";
body += "\nYou can and should change this, when you log in the first time.\n";
body += "\nThe Empire Deluxe Corner\n";
body += "www.givoni.com/empire/";
sendEmail(toaddress, title, body);
}
//Response.Redirect("../player_data.asp");
%>