/// <summary> /// www发送接收数据 /// </summary> /// <param name="bytes"></param> /// <returns></returns> IEnumerator SendMessage(byte[] bytes, uint cmdId) { Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("CONTENT_TYPE", "multipart/form-data"); headers.Add("cmdId", cmdId.ToString()); headers.Add("userId", uid.ToString()); headers.Add("sign", SignTools.Encryption(uid.ToString(), cmdId.ToString())); Debug.Log("发送消息:" + cmdId + " sign=" + SignTools.Encryption(uid.ToString(), cmdId.ToString())); WWW getData = new WWW(Sendlink, bytes, headers); yield return(getData); //try { if (getData.error != null) { Debug.LogError(string.Format("GetData={0}", getData.error)); } else if (getData.text.StartsWith("Error")) { Debug.LogError(getData.text); } else { //解包头 Dictionary <string, string> header = getData.responseHeaders; uint id = uint.Parse(header["CMDID"]); Debug.Log(header["CMDID"]); object obj = Serialization.Deserialize((uint)id, getData.bytes); if (id == NetMessageDef.ResLogin) { protos.Login.ResLogin login = obj as protos.Login.ResLogin; if (login != null) { uid = login.uid; salt = login.salt; Debug.Log("uid=" + uid + " salt=" + salt); } } RequsterNotifier(id, obj, null); } } //catch (System.Exception ex) //{ // Debug.LogWarning(ex.Message); //} }
public void OnReceiveData(uint cmdId, object param1, object param2) { if (cmdId == NetMessageDef.ResLogin) { protos.Login.ResLogin info = param1 as protos.Login.ResLogin; Debug.Log("结果类型:" + info.results); Debug.Log("结果细节:" + info.details); //protos.friend.ReqGetFriendList getFriendList = new protos.friend.ReqGetFriendList(); //getFriendList.feiendId = 1; //GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqGetFriendList, getFriendList)); //protos.friend.ReqGiveVigor giveVigor = new protos.friend.ReqGiveVigor(); //giveVigor.feiendId = 2; //GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqGiveVigor, giveVigor)); //protos.friend.ReqAddFriend addFriend = new protos.friend.ReqAddFriend(); //addFriend.feiendId = 2; //GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqAddFriend, addFriend)); //protos.friend.ReqDeleteFriend addFriend = new protos.friend.ReqDeleteFriend(); //addFriend.feiendId = 2; //GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqDeleteFriend, addFriend)); //protos.friend.ReqFindFriend addFriend = new protos.friend.ReqFindFriend(); //addFriend.name = "王"; //addFriend.page = 1; //addFriend.pageSize = 10; //GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqFindFriend, addFriend)); //protos.integral.ReqAddIntegral addIntegral = new protos.integral.ReqAddIntegral(); //addIntegral.userId = 1; //addIntegral.integral = 10; //GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqAddIntegral, addIntegral)); protos.integral.ReqGetTopList getTopList = new protos.integral.ReqGetTopList(); getTopList.topNums = 10; GameServerMgr.GetInstance().SendMessage(new MuffinMsg((int)NetMessageDef.ReqGetTopList, getTopList)); } else if (cmdId == NetMessageDef.ResFriendList) { protos.friend.ResFriendList list = param1 as protos.friend.ResFriendList; //protos.friend.UserInfo foreach (protos.friend.UserInfo info in list.userInfo) { Debug.Log(string.Format("name={0} lv={1} id={2}", info.name, info.lv, info.uid)); } Debug.Log("好友个数:" + list.userInfo.Count); } else if (cmdId == NetMessageDef.ResReturnDefaultInfo) { protos.ReturnMessage.ResDefaultInfo info = param1 as protos.ReturnMessage.ResDefaultInfo; Debug.Log("结果:" + info.results); Debug.Log("细节:" + info.details); } else if (cmdId == NetMessageDef.ResFindFriendList) { protos.friend.ResFindFriendList list = param1 as protos.friend.ResFindFriendList; foreach (protos.friend.UserInfo info in list.userInfo) { Debug.Log(string.Format("name={0} lv={1} id={2}", info.name, info.lv, info.uid)); } Debug.Log("符合条件用户个数:" + list.userInfo.Count); } else if (cmdId == NetMessageDef.ResGetTopList) { protos.integral.ResGetTopList list = param1 as protos.integral.ResGetTopList; foreach (protos.integral.TopInfo info in list.topInfo) { Debug.Log(string.Format("name={0} lv={1} id={2} integral={3}", info.name, info.lv, info.uid, info.integral)); } Debug.Log("排行榜用户个数:" + list.topInfo.Count); } }