void Awake() { callbacks = new Dictionary <string, CbFunc>(); //初始化 PomeloClient client = new PomeloClient(); client.initClient(host, port, () => { client.connect(null, (data) => { Debug.Log("connect back data" + data.ToString()); JsonObject js = new JsonObject(); js["uid"] = 12234; client.request(router, js, (connectData) => { string conHost = connectData["host"].ToString(); int conPort = int.Parse(connectData["port"].ToString()); Debug.Log(conHost + "#" + conPort.ToString()); client.disconnect(); client = new PomeloClient(); client.initClient(conHost, conPort, () => { client.connect(null, (cb) => { }); }); }); }); }); }
/// <summary> /// 与服务器器建立连接 /// </summary> /// <param name="conResult">Con result.</param> public void Connect(Action <bool> conResult) { connectResultCallback = conResult; if (pclient != null && conResult != null) { Debug.Log("(pclient != null && conResult != null)"); InvokeConnectResult(true); return; } ChangeConnectStatus(ConnectStatus.CONNECTING); EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_REQUEST_START, NetDataRequestTip.startReq); EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_REQUEST_END, NetDataRequestTip.endReq); EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_CONNECT_CLOSE, NetDataRequestTip.ConnectClose); EventDispatcher.Instance().DispatchEvent(NetDataRequestTip.NET_REQUEST_START, null); pclient = new PomeloClient(); pclient.NetWorkStateChangedEvent += OnGateServerNetWorkStateChange; try{ pclient.initClient(CGNetConst.HOST, CGNetConst.POST, () => { pclient.connect(null, conData1 => { Debug.Log("Gate服务器连接成功!"); pclient.request(CGNetConst.ROUTE_LOGIN, delegate(JsonObject jsonObject) { Debug.Log("PARA_CODE = " + jsonObject [CGNetConst.PARA_CODE]); if (Convert.ToInt32(jsonObject [CGNetConst.PARA_CODE]) == CGNetConst.RESULT_CODE_SUC) { Disconnect(true); Debug.Log("与Gate服务器断开连接,准备连接游戏服务器……"); Debug.Log("host=" + (string)jsonObject [CGNetConst.PARA_HOST] + " port=" + jsonObject [CGNetConst.PARA_PORT]); pclient = new PomeloClient(); pclient.NetWorkStateChangedEvent += OnNetWorkStateChange; pclient.initClient((string)jsonObject [CGNetConst.PARA_HOST], Convert.ToInt32(jsonObject [CGNetConst.PARA_PORT]), () => { pclient.connect(null, conData2 => { ChangeConnectStatus(ConnectStatus.CONNECTED); Debug.Log("游戏服务器连接成功!"); // if(conResult != null) // { // conResult(true); // } }); }); } else { Debug.Log("Connect faild!"); InvokeConnectResult(false); // if(conResult != null) // { // conResult(false); // } } }); }); }); }catch (Exception e) { Debug.Log(e.ToString()); } }
public void Request(string route, LuaInterface.LuaTable paramsTable, LuaInterface.LuaFunction func) { if (pc != null) { JsonObject msg = new JsonObject(); IEnumerator <DictionaryEntry> paramList = paramsTable.ToDictTable().GetEnumerator(); while (paramList.MoveNext()) { DictionaryEntry curr = paramList.Current; Debug.Log("key " + curr.Key + " value: " + curr.Value); msg[curr.Key.ToString()] = curr.Value; } pc.request(route, msg, (result) => { PomeloPackage pkg = new PomeloPackage(); if (func == null) { Debug.LogError("callback function is null!"); } pkg.luaFunc = func; pkg.ReturnData = result.ToString(); AddResultPackage(pkg); }); } else { Debug.LogError("Pomelo Client is null"); } }
public void Request(string route, JsonObject data, Action <JsonObject> cb) { if (pclient != null) { pclient.request(route, data, cb); } }
void OnQuery1(object sender, RoutedEventArgs e) { pc1 = new PomeloClient(this.ipAddr.Text, 3014); pc1.connect(null, delegate(JsonObject data) { JsonObject msg = new JsonObject(); msg["userID"] = "demo1"; pc1.request("gate.gateHandler.queryEntry", msg, delegate(JsonObject result) { if (Convert.ToInt32(result["statusCode"]) == 900) { string host = (string)result["host"]; int port = Convert.ToInt32(result["port"]); pc1.disconnect(); pc1.Dispose(); pc1 = null; host1 = host; port1 = port; this.Dispatcher.BeginInvoke((Action)(() => { this.Status11.Text = "success, " + host + ":" + port.ToString(); })); Log1("query success, " + host + ":" + port.ToString()); } else { this.Dispatcher.BeginInvoke((Action)(() => { this.Status11.Text = "error, " + result["message"]; })); Log1("error, " + result["message"]); } }); }); }
//Login the chat application and new PomeloClient. void Login() { string url = "http://114.113.202.141:3088"; pclient = new PomeloClient(url); pclient.init(); JsonObject userMessage = new JsonObject(); userMessage.Add("uid", userName); pclient.request("gate.gateHandler.queryEntry", userMessage, (data) => { System.Object code = null; if (data.TryGetValue("code", out code)) { if (Convert.ToInt32(code) == 500) { return; } else { pclient.disconnect(); pclient = null; System.Object host, port; if (data.TryGetValue("host", out host) && data.TryGetValue("port", out port)) { pclient = new PomeloClient("http://" + "114.113.202.141" + ":" + port.ToString()); pclient.init(); Entry(); } } } }); }
/// <summary> /// request server with a custom data and response /// </summary> /// <param name="route"></param> /// <param name="data"></param> /// <param name="action"></param> public void Request(string route, JsonObject data, Action <JsonObject> action) { m_Conn.request(route, data, (result) => { Dispatcher.Current.BeginInvoke(() => { action.Invoke(result); }); }); }
public void Login(string account, string token) { int port = 5005; mAccount = account; mToken = token; Debug.Log("Login"); pc.initClient(mServer, port, ret => { if (!ret) { Debug.Log("Login initClient fail"); GameAlert.Show("连接服务器失败,请检查网络"); return; } pc.connect(null, data => { JsonObject msg = new JsonObject(); msg ["uid"] = account; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }); }
// 准备按钮的点击事件处理 void Btn_StartGame() { if (btnStart_Flag) // 已经点过了,或者人还没有凑成3个人 { return; } btnStart_Flag = true; GameState = 0; deleteCards.Clear(); // 清空deleteCards的数据 isReadyCount++; JsonObject message = new JsonObject(); message.Add("uid", userName); message.Add("rid", roomid); message.Add("index", index); if (isReadyCount < 3) { pclient.request("chat.chatHandler.isready", message, (data) => { // Debug.Log("已准备好"); }); } if (isReadyCount == 3) { pclient.request("chat.chatHandler.fapai", message, (data) => { Debug.Log("fapai"); }); //pclient.request("chat.chatHandler.fapai", message, getPuke); //pclient.request("chat.chatHandler.fapai", message, (data) => //{ // string tmp = data.ToString(); // JsonData jdtmp = JsonMapper.ToObject(tmp); // string tmp2 = jdtmp["arrayPuke"].ToJson(); // JsonData jdtmp2 = JsonMapper.ToObject(tmp2); // string userIndex = "u" + index.ToString(); // JsonData jdtmpU1 = JsonMapper.ToObject(jdtmp2[userIndex].ToJson()); // for (int i = 0; i < jdtmpU1.Count; i++) // { // string numStr = jdtmpU1[i].ToString(); // int numInt = int.Parse(numStr); // if(!userCardNumber.Contains(numInt)) // userCardNumber.Add(numInt); // } //}); } }
public void syncAuctionInfoRequest(Action <PomeloException, SyncAuctionInfoResponse> cb, object option = null) { var request = new SyncAuctionInfoRequest(); _socket.request <SyncAuctionInfoResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as SyncAuctionInfoResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void getAllAmuletRequest(Action <PomeloException, GetAllAmuletDetailRes> cb, object option = null) { var request = new GetAllAmuletDetailReq(); _socket.request <GetAllAmuletDetailRes>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as GetAllAmuletDetailRes; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void rewardDeskRequest(Action <PomeloException, RewardDeskResponse> cb, object option = null) { var request = new RewardDeskRequest(); _socket.request <RewardDeskResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as RewardDeskResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void dailyRechargeGetInfoRequest(Action <PomeloException, DailyRechargeGetInfoResponse> cb, object option = null) { var request = new DailyRechargeGetInfoRequest(); _socket.request <DailyRechargeGetInfoResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as DailyRechargeGetInfoResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void getVitalityListRequest(Action <PomeloException, GetVitalityListResponse> cb, object option = null) { var request = new GetVitalityListRequest(); _socket.request <GetVitalityListResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as GetVitalityListResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void enterGuildBossAreaRequest(Action <PomeloException, EnterGuildBossAreaResponse> cb, object option = null) { var request = new EnterGuildBossAreaRequest(); _socket.request <EnterGuildBossAreaResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as EnterGuildBossAreaResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void unlockSkillRequest(int s2c_skillId, Action <PomeloException, UnlockSkillResponse> cb, object option = null) { var request = new UnlockSkillRequest(); request.s2c_skillId = s2c_skillId; _socket.request <UnlockSkillResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as UnlockSkillResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void getExchangeLabelRequest(string c2s_npcId, Action <PomeloException, GetExchangeLabelResponse> cb, object option = null) { var request = new GetExchangeLabelRequest(); request.c2s_npcId = c2s_npcId; _socket.request <GetExchangeLabelResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as GetExchangeLabelResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void achievementGetTypeElementRequest(int c2s_id, Action <PomeloException, AchievementGetTypeElementResponse> cb, object option = null) { var request = new AchievementGetTypeElementRequest(); request.c2s_id = c2s_id; _socket.request <AchievementGetTypeElementResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as AchievementGetTypeElementResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void inviteRequest(string c2s_playerId, Action <PomeloException, InviteResponse> cb, object option = null) { var request = new InviteRequest(); request.c2s_playerId = c2s_playerId; _socket.request <InviteResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as InviteResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void packUpBagRequest(int c2s_type, Action <PomeloException, PackUpBagResponse> cb, object option = null) { var request = new PackUpBagRequest(); request.c2s_type = c2s_type; _socket.request <PackUpBagResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as PackUpBagResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void depositItemRequest(int c2s_fromIndex, Action <PomeloException, DepositItemResponse> cb, object option = null) { var request = new DepositItemRequest(); request.c2s_fromIndex = c2s_fromIndex; _socket.request <DepositItemResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as DepositItemResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void getMallScoreItemListRequest(int c2s_type, Action <PomeloException, GetIntergalMallListResponse> cb, object option = null) { var request = new GetIntergalMallListRequest(); request.c2s_type = c2s_type; _socket.request <GetIntergalMallListResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as GetIntergalMallListResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void buyPageRequest(List <int> c2s_sellIndex, Action <PomeloException, BuyPageResponse> cb, object option = null) { var request = new BuyPageRequest(); request.c2s_sellIndex.AddRange(c2s_sellIndex); _socket.request <BuyPageResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as BuyPageResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void getTreasureInfoRequest(int c2s_treasureMsg, Action <PomeloException, GetTreasureInfoResponse> cb, object option = null) { var request = new GetTreasureInfoRequest(); request.c2s_treasureMsg = c2s_treasureMsg; _socket.request <GetTreasureInfoResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as GetTreasureInfoResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void leaderBoardRequest(int c2s_kind, int c2s_season, Action <PomeloException, LeaderBoardResponse> cb, object option = null) { var request = new LeaderBoardRequest(); request.c2s_kind = c2s_kind; request.c2s_season = c2s_season; _socket.request <LeaderBoardResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as LeaderBoardResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void createPlayerRequest(int c2s_pro, string c2s_name, Action <PomeloException, CreatePlayerResponse> cb, object option = null) { var request = new CreatePlayerRequest(); request.c2s_pro = c2s_pro; request.c2s_name = c2s_name; _socket.request <CreatePlayerResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as CreatePlayerResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public void equipFashionRequest(string code, bool ison, Action <PomeloException, EquipFashionResponse> cb, object option = null) { var request = new EquipFashionRequest(); request.code = code; request.ison = ison; _socket.request <EquipFashionResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as EquipFashionResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
// Update is called once per frame void Update() { string route = "connector.entryHandler.send"; if (Input.GetKeyDown(KeyCode.UpArrow)) { JsonObject msg = new JsonObject(); msg["direction"] = "up"; pc.request(route, msg, OnQuery); } if (Input.GetKeyDown(KeyCode.DownArrow)) { JsonObject msg = new JsonObject(); msg["direction"] = "down"; pc.request(route, msg, OnQuery); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { JsonObject msg = new JsonObject(); msg["direction"] = "left"; pc.request(route, msg, OnQuery); } if (Input.GetKeyDown(KeyCode.RightArrow)) { JsonObject msg = new JsonObject(); msg["direction"] = "right"; pc.request(route, msg, OnQuery); } while (upCount > 0) { player.transform.position += new Vector3(0, 1, 0); upCount--; } while (downCount > 0) { player.transform.position += new Vector3(0, -1, 0); downCount--; } while (leftCount > 0) { player.transform.position += new Vector3(-1, 0, 0); leftCount--; } while (rightCount > 0) { player.transform.position += new Vector3(1, 0, 0); rightCount--; } }
public void sendChatRequest(int c2s_scope, string c2s_content, string c2s_serverData, string c2s_acceptRoleId, Action <PomeloException, SendChatResponse> cb, object option = null) { var request = new SendChatRequest(); request.c2s_scope = c2s_scope; request.c2s_content = c2s_content; request.c2s_serverData = c2s_serverData; request.c2s_acceptRoleId = c2s_acceptRoleId; _socket.request <SendChatResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as SendChatResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public static void Main() { JsonObject server = read("./server.json"); string host = (string)server["host"]; int port = Convert.ToInt32(server["port"]); Console.WriteLine("before init"); pc = new PomeloClient(host, port); Console.WriteLine("before connect"); pc.connect(null, delegate(JsonObject data){ Console.WriteLine("after connect " + data.ToString()); JsonObject msg = new JsonObject(); msg["uid"] = 1; pc.request("gate.gateHandler.queryEntry", msg, onQuery); }); while (true) { string str = Console.ReadLine(); if (str != null) { send(str); } System.Threading.Thread.Sleep(100); } }
public static void OnQuery(JsonObject result) { if (Convert.ToInt32(result["code"]) == 200) { pc.disconnect(); string host = (string)result["host"]; int port = Convert.ToInt32(result["port"]); pc = new PomeloClient(); pc.NetWorkStateChangedEvent += (state) => { Console.WriteLine(state); }; pc.initClient(host, port, () => { pc.connect(null, (data) => { JsonObject userMessage = new JsonObject(); Console.WriteLine("on connect to connector!"); //Login JsonObject msg = new JsonObject(); msg["username"] = "******"; msg["rid"] = "pomelo"; pc.request("connector.entryHandler.enter", msg, OnEnter); }); }); } }
//Login the chat application and new PomeloClient. void Login() { string host = "127.0.0.1"; int port = 3014; pc = new PomeloClient(host, port); pc.connect(null, (data)=>{ JsonObject msg = new JsonObject(); msg["uid"] = userName; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }
public static void loginTest(string host, int port) { pc = new PomeloClient(host, port); pc.connect(null, data=>{ Console.WriteLine("on data back" + data.ToString()); JsonObject msg = new JsonObject(); msg["uid"] = 111; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); while(true){ System.Threading.Thread.Sleep(100); }; }
public static void loginTest(string host, int port) { pc = new PomeloClient(); pc.NetWorkStateChangedEvent += (state) => { Console.WriteLine(state); }; pc.initClient(host, port, () => { pc.connect(null, data => { Console.WriteLine("on data back" + data.ToString()); JsonObject msg = new JsonObject(); msg["uid"] = 111; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }); }
public static void OnQuery(JsonObject result) { if(Convert.ToInt32(result["code"]) == 200){ pc.disconnect(); string host = (string)result["host"]; int port = Convert.ToInt32(result["port"]); pc = new PomeloClient(host, port); pc.connect(null, (data)=>{ Console.WriteLine("on connect to connector!"); pc.on(PomeloClient.EVENT_DISCONNECT, onDisconnect); //Login JsonObject msg = new JsonObject(); msg["username"] = "******"; msg["rid"] = "pomelo"; pc.request("connector.entryHandler.enter", msg, OnEnter); }); } }
IEnumerator WaitForLoginRequest(WWW www) { yield return www; // check for errors if (www.error == null) { Debug.Log("WWW Ok!: " + www.text); GameManager.instance.user.userID = www.text.Replace("\"", ""); pclient = GameManager._pclient; if (pclient != null){ pclient.connect(null, data => { Debug.Log ("Connect server ok ..."); JsonObject msg = new JsonObject(); pclient.request(Constants.GATESERVER, msg, OnResponseFromGate); }); } else{ Debug.LogError("Pomelo client null"); } } else { Debug.Log("WWW Error: "+ www.error); } }