244 lines
7.2 KiB
ActionScript
244 lines
7.2 KiB
ActionScript
package net.pixvi.myr.center
|
|
{
|
|
import flash.events.Event;
|
|
import net.pixvi.common.system.language.lang;
|
|
import net.pixvi.common.utils.mobi.MobiTools;
|
|
import net.pixvi.myr.GameMath;
|
|
import net.pixvi.myr.element.user.ServerVo;
|
|
import net.pixvi.myr.net.NetUser;
|
|
import net.pixvi.myrane.MyrAne;
|
|
import net.pixvi.myrloader.center.MyrCenter;
|
|
import net.pixvi.pfw.utils.ArrayUtil;
|
|
import net.pixvi.pfw.utils.Saver;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class AccountCenter
|
|
{
|
|
|
|
public var username:String = "";
|
|
|
|
public var password:String = "";
|
|
|
|
public var userToken:String = "";
|
|
|
|
public var sdkUserId:String = "";
|
|
|
|
public var isVisitor:Boolean = false;
|
|
|
|
public var userServerList:Array;
|
|
|
|
public var userMasterList:Array;
|
|
|
|
public var curServer:ServerVo;
|
|
|
|
public var realName:String;
|
|
|
|
public var realID:String;
|
|
|
|
public var noticeData:Object = {};
|
|
|
|
private var onSdkLoginComplete:Function;
|
|
|
|
private var onLoginComplete:Function;
|
|
|
|
private var onSelectServerComplete:Function;
|
|
|
|
private var onSelectServerError:Function;
|
|
|
|
private var selectServer_serverId:int;
|
|
|
|
public function AccountCenter()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : AccountCenter
|
|
{
|
|
return Singleton.getInstanceOrCreate(AccountCenter) as AccountCenter;
|
|
}
|
|
|
|
public function sdkLogin(sdkUid:String, sdkToken:String, onComplete:Function) : void
|
|
{
|
|
onSdkLoginComplete = onComplete;
|
|
NetUser.getIns().sdkLogin(sdkUid,sdkToken,sdkLoginHandler);
|
|
}
|
|
|
|
private function sdkLoginHandler(re:Object) : void
|
|
{
|
|
userLoginCompleteHandler(re);
|
|
if(onSdkLoginComplete != null)
|
|
{
|
|
onSdkLoginComplete(re);
|
|
onSdkLoginComplete = null;
|
|
}
|
|
}
|
|
|
|
public function login(un:String, pw:String, onComplete:Function) : void
|
|
{
|
|
onLoginComplete = onComplete;
|
|
NetUser.getIns().login(un,pw,loginHandler);
|
|
}
|
|
|
|
private function loginHandler(re:Object) : void
|
|
{
|
|
if(re.re == 0 && re.resCode == 0)
|
|
{
|
|
userLoginCompleteHandler(re);
|
|
}
|
|
if(onLoginComplete != null)
|
|
{
|
|
onLoginComplete(re);
|
|
onLoginComplete = null;
|
|
}
|
|
}
|
|
|
|
private function userLoginCompleteHandler(re:Object) : void
|
|
{
|
|
var maxvo:ServerVo = null;
|
|
var i:int = 0;
|
|
var sData:Object = null;
|
|
var sVo:ServerVo = null;
|
|
var j:int = 0;
|
|
var mData:Object = null;
|
|
var msVo:ServerVo = null;
|
|
logout();
|
|
if(re.re != 0 || re.resCode != 0)
|
|
{
|
|
return;
|
|
}
|
|
AccountCenter.getIns().userToken = re.playerInfo.token;
|
|
userServerList = [];
|
|
var serverDic:Object = {};
|
|
for(i = 0; i < re.servers.length; )
|
|
{
|
|
sData = re.servers[i];
|
|
if(sData.platform == MyrCenter.platform)
|
|
{
|
|
sVo = new ServerVo();
|
|
sVo.channel = sData.channel;
|
|
sVo.platform = sData.platform;
|
|
sVo.gameServerAddress = sData.gameServerAddress;
|
|
sVo.payServerAddress = sData.payServerAddress;
|
|
sVo.serverName = sData.serverName;
|
|
sVo.serverStatus = sData.serverStatus;
|
|
sVo.serverId = sData.id;
|
|
userServerList.push(sVo);
|
|
serverDic[sVo.serverId] = sVo;
|
|
if(maxvo == null || maxvo.serverId < sVo.serverId)
|
|
{
|
|
maxvo = sVo;
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
if(maxvo != null)
|
|
{
|
|
maxvo.isNew = true;
|
|
}
|
|
for(j = 0; j < re.masterInfos.length; )
|
|
{
|
|
mData = re.masterInfos[j];
|
|
msVo = serverDic[mData.serverId];
|
|
if(msVo != null)
|
|
{
|
|
msVo.masterCreateTime = mData.createTime;
|
|
msVo.masterId = mData.id;
|
|
msVo.masterName = mData.masterName;
|
|
msVo.masterUpdateTime = mData.updateTime;
|
|
msVo.masterStatus = mData.status ? 1 : 0;
|
|
msVo.hasMaster = true;
|
|
}
|
|
j++;
|
|
}
|
|
AccountCenter.getIns().realID = re.playerInfo.userIdCard;
|
|
AccountCenter.getIns().realName = re.playerInfo.userName;
|
|
}
|
|
|
|
public function selectServer(serverId:int, onComplete:Function, onError:Function) : void
|
|
{
|
|
onSelectServerComplete = onComplete;
|
|
onSelectServerError = onError;
|
|
selectServer_serverId = serverId;
|
|
NetUser.getIns().selectServer(serverId,selectServerHandler);
|
|
}
|
|
|
|
public function selectServerHandler(re:Object) : void
|
|
{
|
|
if(re.resCode == 994 && GameMath.ModeTrace == false)
|
|
{
|
|
if(onSelectServerError != null)
|
|
{
|
|
onSelectServerError(lang("服务器爆满了!请稍后再来吧!"));
|
|
}
|
|
onSelectServerError = null;
|
|
onSelectServerComplete = null;
|
|
return;
|
|
}
|
|
if(re.resCode == 990)
|
|
{
|
|
if(onSelectServerError != null)
|
|
{
|
|
onSelectServerError(lang("服务器繁忙,请稍后再试吧!"));
|
|
}
|
|
onSelectServerError = null;
|
|
onSelectServerComplete = null;
|
|
return;
|
|
}
|
|
curServer = ArrayUtil.getElementByValue(userServerList,"serverId",selectServer_serverId) as ServerVo;
|
|
if(MobiTools.isMobi() && MyrCenter.channel == "MEIZU" && Boolean(MyrAne.meizu2Bingxue))
|
|
{
|
|
MyrAne.bingxueSetRoleData(1,curServer.serverId,curServer.serverName,curServer.masterId.toString(),curServer.masterName,"1",100,"驯养师","","牧羊人之心");
|
|
}
|
|
if(onSelectServerComplete != null)
|
|
{
|
|
onSelectServerComplete();
|
|
onSelectServerError = null;
|
|
onSelectServerComplete = null;
|
|
}
|
|
}
|
|
|
|
public function logout() : void
|
|
{
|
|
MasterCenter.getIns().masterInfo = null;
|
|
Game.getIns().master = null;
|
|
}
|
|
|
|
public function userUpgrade(e:Event = null) : void
|
|
{
|
|
trace("更新账号类型");
|
|
isVisitor = false;
|
|
}
|
|
|
|
public function userUpgrade2(e:Event = null) : void
|
|
{
|
|
trace("更新账号类型2");
|
|
isVisitor = false;
|
|
}
|
|
|
|
public function get account() : Object
|
|
{
|
|
return Saver.getAuto("accountsave");
|
|
}
|
|
|
|
public function resetAccount() : void
|
|
{
|
|
Saver.removeAuto("accountsave");
|
|
}
|
|
|
|
public function loginOut() : void
|
|
{
|
|
MasterCenter.getIns().masterInfo = null;
|
|
AccountCenter.getIns().userToken = "";
|
|
}
|
|
|
|
public function saveAccount(username:String, password:String) : void
|
|
{
|
|
Saver.saveAuto("accountsave",{
|
|
"username":username,
|
|
"password":password
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|