// Use this for initialization void Start() { m_Socket = new TcpClient(); m_Socket.Connect("192.168.31.236", 8888); m_Stream = m_Socket.GetStream(); LoginC2S msg = new LoginC2S(); msg.name = "huashao"; byte[] dd = ProtobufTool.ProtoBufToBytes <LoginC2S>(msg); int len = dd.Length + 2; Debug.LogError(len); byte[] buf = new byte[len + 6]; buf[0] = (byte)(len & 0xff); buf[1] = (byte)(len >> 8 & 0xff); buf[2] = (byte)(len >> 16 & 0xff); buf[3] = (byte)(len >> 24 & 0xff); buf[4] = 1; buf[5] = 0; Array.Copy(dd, 0, buf, 6, dd.Length); m_Stream.Write(buf, 0, buf.Length); byte[] recv = new byte[1024]; int c = m_Stream.Read(recv, 0, 1024); int rlen = (recv[0] | recv[1] << 8 | recv[2] << 16 | recv[3] << 24); int rId = (recv[4] | recv[5] << 8); Debug.LogError(string.Format("recv len:{0} id:{1}", rlen, rId)); byte [] rbuf = new byte[rlen - 2]; Array.Copy(recv, 6, rbuf, 0, rlen - 2); LoginS2C rmsg = ProtobufTool.BytesToProtoBuf <LoginS2C>(rbuf); Debug.LogError(rmsg.playerId); m_Stream.Close(); m_Socket.Close(); }
/// <summary> /// 发送登陆请求 /// </summary> private void SendLoginRequest() { LoginC2S package = new LoginC2S(); switch (GlobalData.sdkPlatform) { case SDKPlatform.ANDROID: package.mac = PlayerPrefs.GetString(PrefsKey.USERMAC); package.name = PlayerPrefs.GetString(PrefsKey.USERNAME); package.imageUrl = PlayerPrefs.GetString(PrefsKey.HEADURL); package.sex = PlayerPrefs.GetInt(PrefsKey.SEX); break; case SDKPlatform.LOCAL: package.mac = GlobalData.UserMac; package.name = GlobalData.UserName; package.imageUrl = GlobalData.ImageUrl; package.sex = 1; break; } package.psw = GlobalData.UserPwd; NetMgr.Instance.SendBuff <LoginC2S>(SocketType.LOGIN, MsgNoC2S.REQUEST_LOGIN_C2S.GetHashCode(), 0, package); Debug.Log("发送登陆请求"); loginProxy.autoLogin = false; }
public void SendCredentials(LoginType type, string userID = "", string password = "") { loginType = type; this.userID = userID; this.password = password; byte[] stream = null; MsgCode serverChannel = MsgCode.LoginMessage; switch (type) { case LoginType.Guest: { return; } case LoginType.Login: { LoginC2S loginData = new LoginC2S(); loginData.loginName = userID; loginData.password = password; loginData.UDID = DeviceUtil.Instance.GetDeviceUniqueIdentifier(); loginData.MAC = DeviceUtil.Instance.GetDeviceUniqueIdentifier(); loginData.ip = DeviceUtil.Instance.GetDeviceIP(); stream = ProtobufUtils.Serialize(loginData); serverChannel = MsgCode.LoginMessage; UILockManager.SetGroupState(UIEventGroup.Middle, UIEventState.WaitNetwork); break; } case LoginType.Register: { RegisterC2S register = new RegisterC2S(); register.ip = DeviceUtil.Instance.GetDeviceIP(); register.MAC = DeviceUtil.Instance.GetDeviceUniqueIdentifier(); register.loginName = userID; register.passWord = password; stream = ProtobufUtils.Serialize(register); serverChannel = MsgCode.RegisterMessage; UILockManager.SetGroupState(UIEventGroup.Middle, UIEventState.WaitNetwork); break; } } Utils.DebugUtils.Log(Utils.DebugUtils.Type.Login, string.Format("SendCredentials {0} userID: {1} password: {2}", serverChannel.ToString(), userID, password)); Utils.DebugUtils.Log(Utils.DebugUtils.Type.Login, string.Format("Sending {0} as {1} ", type == LoginType.Register ? "RegisterC2S" : "LoginC2S", serverChannel.ToString())); NetworkManager.SendRequest(serverChannel, stream); }
/// <summary> /// 发送登录请求 /// </summary> public void SendLoginRequest(string username, string password) { LoginC2S loginC2S = new LoginC2S(); loginC2S.username = username; loginC2S.password = password; Dictionary <byte, object> data = new Dictionary <byte, object>(); data.Add(1, BinSerializer.Serialize(loginC2S)); PhotonEngine.Peer.OpCustom((byte)OperationCode.Login, data, true); }
void Update() { if (connector != null && connector.Connected) { LoginC2S msg = new LoginC2S(); msg.name = "huashao"; byte[] dd = ProtobufTool.ProtoBufToBytes <LoginC2S>(msg); for (int i = 0; i < 10; i++) { packer.Input((ushort)DemoTypeCmd.LoginReq, dd); Debug.LogError("sendSize:" + packer.CurSize); var await = connector.Send(packer.SendBuf, 0, packer.CurSize); packer.Clear(); } } }
/// <summary> /// 发送登陆请求 /// </summary> private void SendLoginRequest() { LoginC2S package = new LoginC2S(); switch (GlobalData.sdkPlatform) { case SDKPlatform.ANDROID: package.mac = PlayerPrefs.GetString(PrefsKey.USERMAC); package.name = PlayerPrefs.GetString(PrefsKey.USERNAME); package.imageUrl = PlayerPrefs.GetString(PrefsKey.HEADURL); package.sex = PlayerPrefs.GetInt(PrefsKey.SEX); break; case SDKPlatform.IOS: package.mac = PlayerPrefs.GetString(PrefsKey.USERMAC); package.name = PlayerPrefs.GetString(PrefsKey.USERNAME); package.imageUrl = PlayerPrefs.GetString(PrefsKey.HEADURL); package.sex = PlayerPrefs.GetInt(PrefsKey.SEX); break; case SDKPlatform.LOCAL: package.mac = GlobalData.UserMac; package.name = GlobalData.UserName; package.imageUrl = GlobalData.ImageUrl; package.sex = 1; break; } package.psw = GlobalData.UserPwd; string[] str = Application.version.Split('.'); StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.Length; i++) { sb.Append(str[i]); } package.version = int.Parse(sb.ToString()); NetMgr.Instance.SendBuff <LoginC2S>(SocketType.LOGIN, MsgNoC2S.C2S_LOGIN.GetHashCode(), 0, package); Debug.Log("发送登陆请求"); loginProxy.autoLogin = false; }