home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Joystick Magazine 2003 November
/
CD1_JOY_153.iso
/
demos
/
NHL2004Demo.exe
/
fe
/
COMMON
/
js
/
Session.js
< prev
next >
Wrap
Text File
|
2003-08-20
|
19KB
|
585 lines
function Session()
{
var protect = this.createProtection(JAX_Object);
protect.profile = null;
protect.userLKey = "";
protect.username = "";
protect.password = "";
protect.postGame = new Object();
protect.postGame.screenID = "";
protect.postGame.backText = "";
protect.postGame.leagueType = "";
protect.postGame.leagueID = "";
protect.postGame.clubInfo = new Object();
protect.postGame.clubInfo.id = "";
protect.postGame.clubInfo.name = "";
protect.postGame.clubInfo.gmID = "";
protect.postGame.clubInfo.gmName = "";
protect.postGame.clubInfo.desc = "";
protect.postGame.clubInfo.estDate = "";
protect.postGame.clubInfo.rating = "";
protect.postGame.roomInfo = new Object();
protect.postGame.roomInfo.roomName = "";
protect.postGame.roomInfo.roomID = "";
protect.postGame.roomInfo.roomLevel = "";
protect.loginCookie = new JAX_Cookie(top.document, "logindata", 240000);
protect.loginCookie.load();
};
Session.prototype = new JAX_Object;
Session.prototype._resetData = function()
{
var protect = this.getProtection(Session);
protect.profile = null;
protect.userLKey = "";
protect.username = "";
protect.password = "";
protect.postGame = new Object();
protect.postGame.screenID = "";
protect.postGame.leagueType = "";
protect.postGame.leagueID = "";
protect.postGame.clubInfo = new Object();
protect.postGame.clubInfo.id = "";
protect.postGame.clubInfo.name = "";
protect.postGame.clubInfo.gmID = "";
protect.postGame.clubInfo.gmName = "";
protect.postGame.clubInfo.desc = "";
protect.postGame.clubInfo.estDate = "";
protect.postGame.clubInfo.rating = "";
protect.postGame.roomInfo = new Object();
protect.postGame.roomInfo.roomName = "";
protect.postGame.roomInfo.roomID = "";
protect.postGame.roomInfo.roomLevel = "";
protect.loginCookie.destroy();
window.external.GameInterface.BrowserState = "";
};
Session.prototype.getProfile = function()
{
var protect = this.getProtection(Session);
return protect.profile;
};
Session.prototype.getUserName = function()
{
var protect = this.getProtection(Session);
return protect.username;
};
Session.prototype.getPassword = function()
{
var protect = this.getProtection(Session);
return protect.password;
};
Session.prototype.getUserLKey = function()
{
var protect = this.getProtection(Session);
return protect.userLKey;
};
Session.prototype.getLoginCookie = function()
{
var protect = this.getProtection(Session);
if ( (protect.loginCookie.userName) && (protect.loginCookie.passWord) ) {
return protect.loginCookie;
};
return null;
};
Session.prototype.getPostGameLeague = function()
{
var protect = this.getProtection(Session);
if ( (protect.postGame.leagueID) && (protect.postGame.leagueType) ) {
var leagueObj = new Object();
leagueObj.leagueID = protect.postGame.leagueID;
leagueObj.leagueType = protect.postGame.leagueType;
return leagueObj;
};
return null;
};
Session.prototype.setPostGameLeague = function(leagueID, leagueType)
{
var protect = this.getProtection(Session);
protect.postGame.leagueID = (leagueID) ? leagueID : 0;
protect.postGame.leagueType = (leagueType) ? leagueType : 0;
this.saveState();
};
Session.prototype.clearPostGameLeague = function()
{
var protect = this.getProtection(Session);
protect.postGame.leagueID = "";
protect.postGame.leagueType = "";
};
Session.prototype.getPostGameNavigation = function()
{
var protect = this.getProtection(Session);
if (protect.postGame.screenID) {
return protect.postGame.screenID;
};
return "";
};
Session.prototype.getPostGameBackText = function()
{
var protect = this.getProtection(Session);
if (protect) {
if (protect.postGame && protect.postGame.backText) {
return protect.postGame.backText;
};
};
return "";
};
Session.prototype.setPostGameNavigation = function(screenID, backText)
{
if (screenID) {
var protect = this.getProtection(Session);
protect.postGame.screenID = screenID;
protect.postGame.backText = (backText) ? backText : "";
this.saveState();
};
};
Session.prototype.clearPostGameNavigation = function()
{
var protect = this.getProtection(Session);
protect.postGame.screenID = "";
this.saveState();
};
Session.prototype.getPostGameClubInfo = function()
{
var protect = this.getProtection(Session);
if (protect.postGame.clubInfo) {
return protect.postGame.clubInfo;
};
return null;
};
Session.prototype.setPostGameClubInfo = function(cid, cname, gmID, gmName, cdesc, est, crating)
{
var protect = this.getProtection(Session);
protect.postGame.clubInfo.id = cid;
protect.postGame.clubInfo.name = cname;
protect.postGame.clubInfo.gmID = gmID;
protect.postGame.clubInfo.gmName = gmName;
protect.postGame.clubInfo.desc = cdesc;
protect.postGame.clubInfo.estDate = est;
protect.postGame.clubInfo.rating = crating;
if (protect.profile) {
if (protect.profile.getClubID() == cid) {
this.saveState();
};
};
};
Session.prototype.setPostGameRoomInfo = function(roomID, roomLevel, roomName)
{
var protect = this.getProtection(Session);
protect.postGame.roomInfo.roomID = roomID;
protect.postGame.roomInfo.roomLevel = roomLevel;
protect.postGame.roomInfo.roomName = roomName;
this.saveState();
};
Session.prototype.getPostGameRoomInfo = function()
{
var protect = this.getProtection(Session);
return protect.postGame.roomInfo;
};
Session.prototype.setProfile = function(userProfile)
{
if ((userProfile) && (userProfile instanceof User_Profile) ) {
var protect = this.getProtection(Session);
protect.profile = userProfile;
protect.username = userProfile.getName();
this.saveState();
};
};
Session.prototype.isLoggedIn = false;
Session.prototype.onlogin = function() {};
Session.prototype.login = function(userName, passWord, savePass)
{
var protect = this.getProtection(Session);
var host = System.getHostURL();
var bSuccess = true;
userName += "";
passWord += "";
if (userName.match(/\W/g) || passWord.match(/\W/g)) {
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError("::99::" + scMsg('SC_REGERROR_10'));
return;
};
if ( EASOProps.get("login_url") ) { host = EASOProps.get("login_url");};
var gameFeatureID = "2311";
var loginError;
var strParams = "methodCall=login";
strParams += "&screenname=" + userName;
strParams += "&password=" + passWord;
strParams = (EASOProps.get("login_dev") ) ? (strParams + "&game-feature-id=&") : (strParams + "&game-feature-id=" + gameFeatureID + "&");
//System.GUI.loadingDialog.setText(scMsg("SC_RETRIEVING_PROFILE"));
//System.GUI.loadingDialog.show();
gblRRManager.onCancel = function()
{
System.Session._resetData();
return false;
};
try {
var request = new Remote_Request( host + "subsxml/subsxml.jsp", strParams,true);
request.oncomplete = function()
{
try {
var responseNode = request.getValue();
var retStatus="";
var retMessage="";
if (request.isError()) {
loginError = new Error();
loginError.description = request.isError();
loginError.requestFailed = true;
bSuccess = false;
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
if (responseNode.xml) {
retStatus = responseNode.selectSingleNode("subs-interface-reply/status").text;
retMessage = responseNode.selectSingleNode("subs-interface-reply/message").text;
} else {
loginError = new Error();
loginError.description = "::500::Server Not Responding";
bSuccess = false;
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
if (retStatus && retMessage) {
if(retStatus=="0") {
protect.userLKey = responseNode.selectSingleNode("//lkey").text;
protect.username = userName;
protect.password = passWord;
if (savePass) {
protect.loginCookie.addItem("userName", userName, true);
protect.loginCookie.addItem("passWord", passWord, true);
};
} else {
loginError = new Error();
loginError.description = "::" + retStatus + "::" + retMessage;
bSuccess = false;
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
} else {
loginError = new Error();
loginError.description = "::500::Server Not Responding";
bSuccess = false;
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
OnLoginServerCallback();
} catch (e) {
if ( !(e === loginError) ) {
loginError = e;
};
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
};
request.send();
} catch (e) {
if ( !(e === loginError) ) {
loginError = e;
};
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login::logining in send", true);
return;
};
function OnLoginServerCallback()
{
try {
if (!loginError) {
System.GUI.loadingDialog.setText( scMsg("SC_UPDATING_TOKEN"));
host = EASOProps.get("host_url");
var request2 = new Remote_Request( host + "easo/nhl03/on_login.jsp", "", true);
request2.oncomplete = function()
{
LoadProfile();
};
request2.send();
} else {
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login::onlogin", true);
return
};
} catch (e) {
if ( !(e === loginError) ) {
loginError = e;
};
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login::onlogin", true);
return;
};
};
function LoadProfile()
{
try {
if (!loginError) {
function onProfileLoaded()
{
try {
System.GUI.profile_viewer.loadProfile(protect.profile);
System.GUI.profile_viewer.hideLogin();
if (System.Session.getProfile().getClubID()) {
System.Session.setPostGameClubInfo(System.Session.getProfile().getClubID());
System.GUI.commandBar.showMyClub();
} else {
System.GUI.commandBar.hideMyClub();
};
System.Session.saveState();
ConnectBuddyList();
} catch (e) {
System.GUI.loadingDialog.hide();
if ( !(e === loginError) ) {
loginError = e;
};
System.GUI.profile_viewer.setLoginInfo("", "");
System.Session.onlogin(false);
System.Session.logout(true);
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
};
protect.profile = new User_Profile();
protect.profile.load(userName, null, onProfileLoaded);
} else {
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
} catch (e) {
if ( !(e === loginError) ) { loginError = e; };
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
};
function ConnectBuddyList()
{
try {
if (!loginError) {
bl_connect();
System.GUI.showBuddyList();
} else {
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
} catch (e) {
System.Session.onlogin(false);
System.Session.logout(true);
System.GUI.profile_viewer.setLoginInfo("", "");
System.handleError(loginError.description, loginError.number, "Session::login", true);
return;
};
if (top.document.frames['Editorial_Frame'].showLoginInfo) {
top.document.frames['Editorial_Frame'].showLoginInfo();
};
System.isOnline = true;
top.document.all.btn_logout.style.visibility = "visible";
System.GUI.playSFX(25);
System.GUI.loadingDialog.hide();
if (System.Session.onlogin && typeof(System.Session.onlogin == "function")) { System.Session.onlogin(true); };
};
};
Session.prototype.logout = function(bDontNav)
{
var protect = this.getProtection(Session);
var bNavigate = true;
if (!bDontNav) {
if (System.GUI.currentScreenObj && parseInt(System.GUI.currentScreenObj.getScreenID()) != 1) {
bNavigate = System.GUI.navigate("1");
} else {
bNavigate = true;
};
};
if (bNavigate) {
this.isLoggedIn = false;
this._resetData();
//System.GUI.profile_viewer.showLogin();
top.document.all.btn_logout.style.visibility = "hidden";
//bl_disconnect();
System.GUI.showChyron();
//Elite_UnloadData();
var prop;
for (prop in System.ScratchPad)
{
System.ScratchPad[prop] = null;
delete System.ScratchPad[prop];
};
System.ScratchPad.EliteCache = new EliteCacheObject;
if (top.document.frames['Editorial_Frame'].hideLoginInfo) {
top.document.frames['Editorial_Frame'].hideLoginInfo();
};
System.GUI.commandBar.hideMyClub();
window.external.PumpMessages();
};
};
Session.prototype.relogin = function(sUserName, sPass)
{
this._resetData();
this.login(sUserName, sPass);
};
Session.prototype.quit = function()
{
//EASO CHECK
if (window.external.GameInterface.LeagueServerInterface.LeagueType == 2)
{
oGameFace.CommInterface.ReportNoStart();
oGameFace.CommInterface.PurgeGameReporter();
}
//function ReallyQuit()
//{
window.external.GameInterface.RestoreGameState();
window.external.GameInterface.Quit();
//};
/*
var bNavigate = false;
if (System.GUI.currentScreenObj && parseInt(System.GUI.currentScreenObj.getScreenID()) != 1) {
bNavigate = System.GUI.navigate("1");
} else {
bNavigate = true;
};
if (bNavigate) {
if (System.GUI.dialog) {
System.GUI.dialog.innerHTML = nhlMsg("ARE_YOU_SURE_YOU_WANT_TO_QUIT");
System.GUI.dialog.addButton("quitBtn", scMsg("SC_YES"), ReallyQuit, true);
System.GUI.dialog.addButton("cancelBtn", scMsg("SC_NO"), null);
System.GUI.dialog.setSize(390, 97);
System.GUI.dialog.allowResize();
System.GUI.dialog.align = "center";
System.GUI.playSFX("alert");
System.GUI.dialog.show();
};
};
*/
bNavigate = null;
};
Session.prototype.saveState = function()
{
var protect = this.getProtection(Session);
var stateObj = new JAX_Object();
stateObj.userLKey = protect.userLKey;
stateObj.username = protect.username;
stateObj.password = protect.password;
var postGameProp;
stateObj.postGame = new Object();
for (postGameProp in protect.postGame)
{
if (typeof protect.postGame[postGameProp] == 'object') { continue; };
stateObj.postGame[postGameProp] = protect.postGame[postGameProp];
};
if (protect.profile) {
if (protect.postGame.clubInfo.id && protect.profile.getClubID()) {
if (protect.postGame.clubInfo.id != protect.profile.getClubID()) {
protect.postGame.clubInfo.id = protect.profile.getClubID();
protect.postGame.clubInfo.name = protect.profile.getClubName();
if (protect.profile.isClubGM()) {
protect.postGame.clubInfo.gmID = protect.profile.getUserID();
protect.postGame.clubInfo.gmName = protect.profile.getName();
};
protect.postGame.clubInfo.rating = protect.profile.getBaseStats().getRating();
};
};
};
var clubProp;
stateObj.postGame.clubInfo = new Object();
for (clubProp in protect.postGame.clubInfo)
{
if (typeof protect.postGame.clubInfo[clubProp] == 'object') {continue; };
if (!protect.postGame.clubInfo[clubProp]) {
stateObj.postGame.clubInfo[clubProp] = "";
} else {
stateObj.postGame.clubInfo[clubProp] = protect.postGame.clubInfo[clubProp];
};
};
var roomProp;
stateObj.postGame.roomInfo = new Object();
for (roomProp in protect.postGame.roomInfo)
{
if (typeof protect.postGame.roomInfo[roomProp] == 'object') { continue; };
if (!protect.postGame.roomInfo[roomProp]) {
stateObj.postGame.roomInfo[roomProp] = "";
} else {
stateObj.postGame.roomInfo[roomProp] = protect.postGame.roomInfo[roomProp];
};
};
window.external.GameInterface.BrowserState = stateObj.toXMLString(true);
};
Session.prototype.loadState = function()
{
var protect = this.getProtection(Session);
var xmlDom = new ActiveXObject("MSXML.DOMDocument");
xmlDom.async = false;
if (window.external.GameInterface.BrowserState) {
var bLoaded = xmlDom.loadXML(window.external.GameInterface.BrowserState);
if (bLoaded) {
var arProps = xmlDom.selectNodes("OBJECT/PROPERTY");
var idx = 0;
var end = (arProps) ? arProps.length : 0;
while (idx < end)
{
protect[arProps[idx].getAttribute("name")] = arProps[idx].text;
idx++;
};
var arPostGameProps = xmlDom.selectNodes("OBJECT/OBJECT/PROPERTY");
idx = 0;
end = (arPostGameProps) ? arPostGameProps.length : 0;
while (idx < end) {
protect.postGame[arPostGameProps[idx].getAttribute("name")] = arPostGameProps[idx].text;
idx++;
};
var arClubInfoProps = xmlDom.selectNodes("/OBJECT/OBJECT/OBJECT[0]/PROPERTY");
idx = 0;
end = (arClubInfoProps) ? arClubInfoProps.length : 0;
while (idx < end) {
protect.postGame.clubInfo[arClubInfoProps[idx].getAttribute("name")] = arClubInfoProps[idx].text;
idx++;
};
var arRoomInfoProps = xmlDom.selectNodes("OBJECT/OBJECT/OBJECT[1]/PROPERTY");
idx = 0;
end = (arRoomInfoProps) ? arRoomInfoProps.length : 0;
while (idx < end) {
protect.postGame.roomInfo[arRoomInfoProps[idx].getAttribute("name")] = arRoomInfoProps[idx].text;
idx++;
};
if ( (protect.username) && (protect.userLKey) && (protect.password) ) {
return true;
} else if ( !isNaN(parseInt(protect.postGame.screenID)) ) {
return true;
};
};
};
return false;
};