int ConnectGateServer(Message _msg) { Debug.Log("connect gate server start"); GameManager.Instance.GamePause(); m_Net.DisConnect(); ServerInfo gateserver = ServerInfo.Parser.ParseFrom(_msg.m_data); if (m_Net.ConnectServer(gateserver.MIp, gateserver.MPort) < 0) { return(-1); } MsgHead msg_head = new MsgHead { m_usrid = _msg.m_usrid }; byte[] data = new byte[16]; msg_head.EnCode(data, 0); m_Net.Send(data, 16); UIManager.Instance.ClosePanel("LoginPanel"); UIManager.Instance.ShowPanel("PanelMain"); GameManager.Instance.GameStart(); Debug.Log("connect gate server end"); return(0); }
public void ExitGame() { MsgHead msg = new MsgHead(); msg.m_type = (uint)EventType.EXIT; msg.m_len = 0; msg.m_usrid = mainPlayerID; msg.m_errID = 0; byte[] temp = new byte[MsgHead.headsize()]; msg.EnCode(temp, 0); m_Net.Send(temp, MsgHead.headsize(), 0); m_Net.DisConnect(); Invoke(nameof(Application.Quit), 1f); }
public int SendMessage <T>(T _protobuffer, EventType mode) where T : global::Google.Protobuf.IMessage <T>, new() { Debug.Log("sendmessage type " + mode); m_msgHeadSend.setType(mode); byte[] tmp = Google.Protobuf.MessageExtensions.ToByteArray(_protobuffer); m_msgHeadSend.m_len = (UInt32)tmp.Length; Debug.Log("protobuf size is " + _protobuffer.CalculateSize()); Debug.Log("head.type is" + m_msgHeadSend.m_type + "head.id is" + m_msgHeadSend.m_usrid + "protobuf size is " + m_msgHeadSend.m_len); m_msgHeadSend.EnCode(m_sendbuf, 0); tmp.CopyTo(m_sendbuf, MsgHead.headsize()); if (Send(m_sendbuf, m_msgHeadSend.m_len + MsgHead.headsize()) < 0) { return(-1); } return(0); }