//直接发送心跳,有的地方有这种需求 public void SendHeartMsgDirect() { //Log.info(this, "Send HeartMsg"); var msdata = new MemoryStream(); Module_1.write_1_0(msdata); AppNet.gameNet.send(msdata, 1, 0); lastSendTime = RealTime.time; sendCount++; }
/**注册Socket数据返回监听**/ /**创建角色 * @param carser 职业[1:斩魂,2:武尊,3:玄天] * @param sex 性别[1:女,2:男] * @param roleName 角色名称 * @param platformName 平台账号名 * **/ public void createRole(int carser, int sex, String roleName) { var msdata = new MemoryStream(); Module_1.write_1_3(msdata, roleName, (byte)carser, (byte)sex, (uint)serverId); Log.debug(this, "-createRole 发送创建角色消息,carser:" + carser + " sex:" + sex + " roleName:" + roleName + " platforName:" + _platformName); AppNet.gameNet.send(msdata, 1, 3); }
/************************************************************************/ /* 获取角色列表 */ /************************************************************************/ public void getRoleList() { var msdata = new MemoryStream(); byte fcm = 1; if (AppStart.RunMode == 0) { Log.info(this, "发送1-1协议"); Module_1.write_1_1(msdata, userName, "", fcm, "ios", "", 0); } else if (AppStart.RunMode != 0) { Log.info(this, "发送1-1协议"); Module_1.write_1_1(msdata, _suid, _signStr, fcm, platform, _verifyToken, uint.Parse(_timestamp)); } AppNet.gameNet.send(msdata, 1, 1); }
//发送客户端信息 public void SendClientInfo() { string os = SystemInfo.operatingSystem; string os_ver = "2.3.4"; string device = SystemInfo.deviceModel; string deviceType = SystemInfo.deviceType.ToString(); string screen = Screen.width + "*" + Screen.height; string mno = "中国移动"; string nm = "wifi"; Log.info(this, "发送1-6客户端信息给服务端:" + os + "," + os_ver + "," + device + "," + deviceType + "," + screen + "," + mno + "," + nm + "," + platform + "," + serverId + ","); var msdata = new MemoryStream(); platform = AppStart.RunMode == 2 ? "91" : "4399"; Module_1.write_1_6(msdata, os, os_ver, device, deviceType, screen, mno, nm, platform, (uint)serverId); AppNet.gameNet.send(msdata, 1, 6); }
/**发送心跳**/ public void SendHeartMsg() { float time = RealTime.time; if (heartGap == 0) { heartGap = 5; } if (sendCount == reciveCount && time - lastSendTime >= heartGap) { Log.info(this, "Send HeartMsg"); var msdata = new MemoryStream(); Module_1.write_1_0(msdata); AppNet.gameNet.send(msdata, 1, 0); lastSendTime = time; sendCount++; } else if (lastSendTime > time) { lastSendTime = time; } }
/// <summary> /// 获取角色列表返回 /// </summary> private void Fun_1_1(INetData data) { var loginMsg = new LoginLoginMsg_1_1(); loginMsg.read(data.GetMemoryStream()); PLoginInfo[] loginInfoArrary = loginMsg.loginInfo.ToArray(); if (loginMsg.code != 0) { Log.info(this, "-Fun_1_1 登陆失败!code:" + loginMsg.code); if (loginMsg.code == 12) { Log.debug(this, "没有创建角色,进入角色创建界面"); Singleton <LoginView> .Instance.CloseView(); if (!startMoviePlayed) { startMoviePlayed = true; //如果没有创建角色,播放开场动画、开场音乐 MovieStart1PlayStart(); } } else { // ErrorCodeManager.ShowError(loginMsg.code); SysErrorCodeVo errorCodeVo = BaseDataMgr.instance.GetErrorCodeVo(uint.Parse(loginMsg.code.ToString(CultureInfo.InvariantCulture))); string result = ""; if (errorCodeVo == null) { result = string.Format("Errorcode {0} is not defined", loginMsg.code); } else { result = errorCodeVo.desc; } ConfirmMgr.Instance.ShowOkAlert(result + ",退出游戏再试一次吧,亲~", ConfirmCommands.OK_CANCEL, QuitGame, LanguageManager.GetWord("ConfirmView.Ok")); } } else { Log.debug(this, "-Fun_1_1 登录成功,获取登陆角色信息:"); for (int i = 0; i < loginInfoArrary.Length; ++i) { Log.debug(this, "id: " + loginInfoArrary[i].id); Log.debug(this, "name: " + loginInfoArrary[i].name); Log.debug(this, "job: " + loginInfoArrary[i].job); Log.debug(this, "level: " + loginInfoArrary[i].level); Log.debug(this, "sex id: " + loginInfoArrary[i].sex); Log.debug(this, "lastLoginTime: " + loginInfoArrary[i].lastLoginTime); Log.debug(this, "serverId: " + loginInfoArrary[i].serverId); } Log.debug(this, "-Fun_1_1 默认选择第一个游戏角色进入游戏"); MeVo.instance.Id = loginInfoArrary[0].id; myID = MeVo.instance.Id; //保存我自己的ID MeVo.instance.Name = loginInfoArrary[0].name; MeVo.instance.job = loginInfoArrary[0].job; MeVo.instance.Level = loginInfoArrary[0].level; MeVo.instance.sex = loginInfoArrary[0].sex; MeVo.instance.lastLoginTime = loginInfoArrary[0].lastLoginTime; MeVo.instance.serverId = loginInfoArrary[0].serverId; var msdata = new MemoryStream(); Module_1.write_1_2(msdata, MeVo.instance.Id); AppNet.gameNet.send(msdata, 1, 2); SoundMgr.Instance.PlaySceneAudio(SoundId.Music_EnterGame); } }