//------------------------------------------------------------------------- public async Task pushData(CouchbaseQueData que_data) { ulong seq = await DbClientCouchbase.Instance.IncrementAsync(QueKeyPrefix); que_data.seq = seq; que_data.que_id = QueId; string key = string.Format("{0}_{1}", QueKeyPrefix, seq); string data = EbTool.jsonSerialize(que_data); await DbClientCouchbase.Instance.asyncSave(key, data); }
//------------------------------------------------------------------------- async void c2sPlayerRankingRequest(PlayerRankingRequest ranking_request) { IRpcSession s = EntityMgr.LastRpcSession; ClientInfo client_info = CoApp.getClientInfo(s); if (client_info == null) { return; } var task = await Task.Factory.StartNew <Task <MethodData> >(async() => { MethodData method_data = new MethodData(); method_data.method_id = MethodType.c2sPlayerRankingRequest; method_data.param1 = EbTool.protobufSerialize <PlayerRankingRequest>(ranking_request); MethodData r = null; try { var grain_playerproxy = GrainClient.GrainFactory.GetGrain <ICellPlayer>(new Guid(client_info.et_player_guid)); r = await grain_playerproxy.c2sRequest(method_data); } catch (Exception ex) { EbLog.Error(ex.ToString()); } return(r); }); if (task.Status == TaskStatus.Faulted || task.Result == null) { if (task.Exception != null) { EbLog.Error(task.Exception.ToString()); } return; } MethodData result = task.Result; if (result.method_id == MethodType.None) { return; } lock (CoApp.RpcLock) { var ranking_response = EbTool.protobufDeserialize <PlayerRankingResponse>(result.param1); CoApp.rpcBySession(s, (ushort)MethodType.s2cPlayerRankingResponse, ranking_response); } }
//------------------------------------------------------------------------- public void changeLocalDataVersionToRemote() { LocalVersionInfo info; info.data_version = RemoteVersionInfo.data_version; info.remote_version_url = ""; LocalVersionInfo = info; string data = EbTool.jsonSerialize(LocalVersionInfo); PlayerPrefs.SetString(AutoPatcherStringDef.PlayerPrefsKeyLocalVersionInfo, data); }
//--------------------------------------------------------------------- // 保存登录帐号信息 public void SaveLoginAccountInfo(string acc, string pwd) { var login_accinfo = new LoginAccountInfo(); login_accinfo.account_name = acc; login_accinfo.pwd = pwd; LoginAccountInfo = login_accinfo; string s = EbTool.jsonSerialize(LoginAccountInfo); PlayerPrefs.SetString(KeyLoginAccountInfo, s); }
//------------------------------------------------------------------------- // 请求举报玩家 public void requestReprotPlayer(string player_etguid, ReportPlayerType report_type) { ReportPlayer report = new ReportPlayer(); report.player_etguid = player_etguid; report.report_type = report_type; PlayerRequest player_request; player_request.id = PlayerRequestId.ReportPlayer; player_request.data = EbTool.protobufSerialize <ReportPlayer>(report); CoApp.rpc(MethodType.c2sPlayerRequest, player_request); }
//------------------------------------------------------------------------- bool _checkResponse <TResponse>(WWW www, Action <UCenterResponseStatus, TResponse, UCenterError> handler) { if (www != null) { if (www.isDone) { UCenterResponse <TResponse> response = null; if (string.IsNullOrEmpty(www.error)) { try { response = EbTool.jsonDeserialize <UCenterResponse <TResponse> >(www.text); } catch (Exception ex) { EbLog.Error("ClientUCenterSDK.update() UCenterResponse Error"); EbLog.Error(ex.ToString()); } } else { EbLog.Error(www.url); EbLog.Error(www.error); } www = null; if (handler != null) { if (response != null) { handler(response.Status, response.Result, response.Error); } else { var error = new UCenterError(); error.ErrorCode = UCenterErrorCode.ServiceUnavailable; error.Message = ""; handler(UCenterResponseStatus.Error, default(TResponse), error); } handler = null; } return(true); } } return(false); }
//------------------------------------------------------------------------- public void requestOperateItem(string operate_id, string item_objid) { ItemOperate item_operate = new ItemOperate(); item_operate.operate_id = operate_id; item_operate.item_objid = item_objid; BagRequest bag_request; bag_request.id = BagRequestId.OperateItem; bag_request.data = EbTool.protobufSerialize <ItemOperate>(item_operate); DefaultRpcSession.rpc((ushort)MethodType.c2sBagRequest, bag_request); }
//------------------------------------------------------------------------- // 请求搜索牌桌 public void requestSearchDesktop(DesktopSearchFilter search_filter) { // 开始转菊花 //UiHelper.CreateWaiting("正在找牌桌...", false); DesktopSearchFilter = search_filter; PlayerLobbyRequest lobby_request; lobby_request.id = PlayerLobbyRequestId.SearchDesktop; lobby_request.data = EbTool.protobufSerialize(search_filter); CoApp.rpc(MethodType.c2sPlayerLobbyRequest, lobby_request); }
//----------------------------------------------------------------------------- public override void fromJsonString(string json_str) { mValue = EbTool.jsonDeserialize <T>(json_str); if (mComponentDef != null && mPropDef.CollectDirty) { mComponentDef._tryAddDirtyProp(this); } if (OnChanged != null) { OnChanged(this, null); } }
//--------------------------------------------------------------------- // 加载登录帐号信息 public LoginAccountInfo LoadLoginAccountInfo() { if (PlayerPrefs.HasKey(KeyLoginAccountInfo)) { string s = PlayerPrefs.GetString(KeyLoginAccountInfo); LoginAccountInfo = EbTool.jsonDeserialize <LoginAccountInfo>(s); } else { LoginAccountInfo = new LoginAccountInfo(); } return(LoginAccountInfo); }
//------------------------------------------------------------------------- public Task <MethodData> c2sPlayerTradeRequest(MethodData method_data) { MethodData result = new MethodData(); result.method_id = MethodType.None; var playertrade_request = EbTool.protobufDeserialize <PlayerTradeRequest>(method_data.param1); switch (playertrade_request.id) { case PlayerTradeRequestId.MallGetItemList: // c->s, 商会,请求获取商品列表 { EbLog.Note("CellPlayerTrade.c2sPlayerTradeRequest() MallGetItemList"); //var request = EbTool.protobufDeserialize<PlayerWorkRoomRequestCompound>(playertrade_request.data); //PlayerWorkRoomResponseCompound data; //data.result = ProtocolResult.Success; //data.item_data = null; //PlayerWorkRoomResponse workroom_response; //workroom_response.id = PlayerWorkRoomResponseId.Compound; //workroom_response.data = EbTool.protobufSerialize<PlayerWorkRoomResponseCompound>(data); //result.method_id = MethodType.s2cPlayerWorkRoomResponse; //result.param1 = EbTool.protobufSerialize<PlayerWorkRoomResponse>(workroom_response); } break; case PlayerTradeRequestId.MallBuyItem: // c->s, 商会,请求购买商品 { } break; case PlayerTradeRequestId.MallSellItem: // c->s, 商会,请求出售商品 { } break; case PlayerTradeRequestId.MallGetItemPrice: // c->s, 商会,请求获取商品价格 { } break; default: break; } return(Task.FromResult(result)); }
//------------------------------------------------------------------------- // 请求是否同意添加好友 public void requestAgreeAddFriend(string player_etguid, bool agree) { AddFriendAgree addfriend_agree; addfriend_agree.player_etguid = player_etguid; addfriend_agree.agree = agree; PlayerFriendRequest playerfriend_request; playerfriend_request.id = PlayerFriendRequestId.AgreeAddFriend; playerfriend_request.data = EbTool.protobufSerialize <AddFriendAgree>(addfriend_agree); CoApp.rpc(MethodType.c2sPlayerFriendRequest, playerfriend_request); }
//------------------------------------------------------------------------- public async Task <MethodData> c2sPlayerRankingRequest(MethodData method_data) { MethodData result = new MethodData(); result.method_id = MethodType.None; var ranking_request = EbTool.protobufDeserialize <PlayerRankingRequest>(method_data.param1); switch (ranking_request.id) { case PlayerRankingRequestId.GetRankingList: { EbLog.Note("CellPlayerRanking.c2sPlayerRankingRequest() GetRankingList"); var ranking_list_type = EbTool.protobufDeserialize <RankingListType>(ranking_request.data); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_playerservice = grain.GF.GetGrain <ICellPlayerService>(0); PlayerRankingResponse ranking_response; ranking_response.id = PlayerRankingResponseId.None; ranking_response.data = null; if (ranking_list_type == RankingListType.Chip) { var list_rankingchip = await grain_playerservice.getChipRankingList(); ranking_response.id = PlayerRankingResponseId.GetChipRankingList; ranking_response.data = EbTool.protobufSerialize <List <RankingChip> >(list_rankingchip); } else if (ranking_list_type == RankingListType.VIPPoint) { var list_rankingvippoint = await grain_playerservice.getVIPPointRankingList(); ranking_response.id = PlayerRankingResponseId.GetVIPPointRankingList; ranking_response.data = EbTool.protobufSerialize <List <RankingVIPPoint> >(list_rankingvippoint); } result.method_id = MethodType.s2cPlayerRankingResponse; result.param1 = EbTool.protobufSerialize <PlayerRankingResponse>(ranking_response); } break; default: break; } return(result); }
//--------------------------------------------------------------------- // 删除好友 public Task s2sProxyDeleteFriend(string friend_etguid) { Dictionary <string, PlayerInfo> map_friend = Def.mPropMapFriend.get(); map_friend.Remove(friend_etguid); // 通知本地客户端删除好友 PlayerFriendNotify friend_notify; friend_notify.id = PlayerFriendNotifyId.DeleteFriend; friend_notify.data = EbTool.protobufSerialize(friend_etguid); _onFriendNotify(friend_notify); return(TaskDone.Done); }
//--------------------------------------------------------------------- public async Task onDesktopStreamEvent(StreamData data) { MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.None; if (string.IsNullOrEmpty(DesktopEtGuid)) { goto End; } switch (data.event_id) { case StreamEventId.DesktopStreamEvent: // 通知成员更新 { var desktop_notify = (DesktopNotify)data.param1; switch (desktop_notify.id) { case DesktopNotifyId.PlayerChat: { var msg_recv = EbTool.protobufDeserialize <ChatMsgRecv>(desktop_notify.data); CoPlayer.CoPlayerChat.s2sRecvChatFromDesktop(msg_recv); } break; default: { notify_data.method_id = MethodType.s2cPlayerDesktopNotify; notify_data.param1 = EbTool.protobufSerialize(desktop_notify); } break; } } break; default: break; } End: if (notify_data.method_id != MethodType.None) { var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); await grain_player.s2sNotify(notify_data); } }
//------------------------------------------------------------------------- // 玩家通知 void s2cPlayerNotify(MethodData method_data) { var client_info = CoApp.getClientInfo(Session); if (client_info == null) { return; } var player_notify = EbTool.protobufDeserialize <PlayerNotify>(method_data.param1); lock (CoApp.RpcLock) { CoApp.rpcBySession(Session, (ushort)MethodType.s2cPlayerNotify, player_notify); } }
//------------------------------------------------------------------------- public void s2cEquipNotifyTakeoff(EquipSlot equip_slot) { EquipNotify equip_notify; equip_notify.id = EquipNotifyId.TakeoffEquip; equip_notify.data = EbTool.protobufSerialize <EquipSlot>(equip_slot); MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.s2cEquipNotify; notify_data.param1 = EbTool.protobufSerialize <EquipNotify>(equip_notify); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); grain_player.s2sNotify(notify_data); }
//------------------------------------------------------------------------- public void s2cStatusNotifyCreateStatus(ItemData item_data) { StatusNotify status_notify; status_notify.id = StatusNotifyId.CreateStatus; status_notify.data = EbTool.protobufSerialize <ItemData>(item_data); MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.s2cStatusNotify; notify_data.param1 = EbTool.protobufSerialize <StatusNotify>(status_notify); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); grain_player.s2sNotify(notify_data); }
//------------------------------------------------------------------------- // 控制台命令添加道具 public void requestDevconsoleAddItem(int item_id, int count) { EbLog.Note("ClientPlayer.devconsoleAddItem() item_id=" + item_id + " count=" + count); Dictionary <byte, string> map_param = new Dictionary <byte, string>(); map_param[0] = "AddItem";// Cmd map_param[1] = item_id.ToString(); map_param[2] = count.ToString(); PlayerRequest player_request; player_request.id = PlayerRequestId.DevConsoleCmd; player_request.data = EbTool.protobufSerialize <Dictionary <byte, string> >(map_param); CoApp.rpc(MethodType.c2sPlayerRequest, player_request); }
//------------------------------------------------------------------------- // 控制台命令操作道具 public void requestDevconsoleOperateItem(ushort item_objid, string operate_id) { EbLog.Note("ClientPlayer.devconsoleOperateItem() item_objid=" + item_objid); Dictionary <byte, string> map_param = new Dictionary <byte, string>(); map_param[0] = "OperateItem";// Cmd map_param[1] = operate_id; map_param[2] = item_objid.ToString(); PlayerRequest player_request; player_request.id = PlayerRequestId.DevConsoleCmd; player_request.data = EbTool.protobufSerialize <Dictionary <byte, string> >(map_param); CoApp.rpc(MethodType.c2sPlayerRequest, player_request); }
//------------------------------------------------------------------------- // 控制台命令设置自己等级 public void requestDevconsoleSetLevel(int level, int exp) { EbLog.Note("ClientPlayer.devconsoleSetLevel() level=" + level + " exp=" + exp); Dictionary <byte, string> map_param = new Dictionary <byte, string>(); map_param[0] = "SetLevel";// Cmd map_param[1] = level.ToString(); map_param[2] = exp.ToString(); PlayerRequest player_request; player_request.id = PlayerRequestId.DevConsoleCmd; player_request.data = EbTool.protobufSerialize <Dictionary <byte, string> >(map_param); CoApp.rpc(MethodType.c2sPlayerRequest, player_request); }
//------------------------------------------------------------------------- public void s2cBagNotifyUpdateItem(ItemData item_data) { BagNotify bag_notify; bag_notify.id = BagNotifyId.UpdateItem; bag_notify.data = EbTool.protobufSerialize <ItemData>(item_data); MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.s2cBagNotify; notify_data.param1 = EbTool.protobufSerialize <BagNotify>(bag_notify); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); grain_player.s2sNotify(notify_data); }
//------------------------------------------------------------------------- void _s2cChatMsg(ChatMsgRecv msg_recv) { PlayerChatNotify playerchat_notify; playerchat_notify.id = PlayerChatNotifyId.RecvChatMsg; playerchat_notify.data = EbTool.protobufSerialize <ChatMsgRecv>(msg_recv); MethodData method_data = new MethodData(); method_data.method_id = MethodType.s2cPlayerChatNotify; method_data.param1 = EbTool.protobufSerialize <PlayerChatNotify>(playerchat_notify); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); grain_player.s2sNotify(method_data); }
//--------------------------------------------------------------------- public async Task onFriendStreamEvent(StreamData data) { MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.None; switch (data.event_id) { case StreamEventId.FriendStreamEvent: { var friend_notify = (PlayerFriendNotify)data.param1; switch (friend_notify.id) { case PlayerFriendNotifyId.OnFriendLogin: { //var d = EbTool.protobufDeserialize<DesktopNotifyDesktopPreFlopS>(desktop_notify.data); //DesktopNotify dn; //dn.id = DesktopNotifyId.DesktopPreFlop; //dn.data = EbTool.protobufSerialize(desktop_preflop); //notify_data.method_id = MethodType.s2cPlayerDesktopNotify; //notify_data.param1 = EbTool.protobufSerialize(dn); } break; default: { notify_data.method_id = MethodType.s2cPlayerDesktopNotify; notify_data.param1 = EbTool.protobufSerialize(friend_notify); } break; } } break; default: break; } End: if (notify_data.method_id != MethodType.None) { var grain = Entity.getUserData <GrainCellPlayer>(); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); await grain_player.s2sNotify(notify_data); } }
//------------------------------------------------------------------------- // 请求赠送玩家筹码 public void requestGivePlayerChip(string player_etguid, int chip) { PlayerInfo player_info = new PlayerInfo(); player_info.player_etguid = player_etguid; GivePlayerChip give_chip = new GivePlayerChip(); give_chip.player_info = player_info; give_chip.chip = chip; PlayerRequest player_request; player_request.id = PlayerRequestId.GivePlayerChip; player_request.data = EbTool.protobufSerialize <GivePlayerChip>(give_chip); CoApp.rpc(MethodType.c2sPlayerRequest, player_request); }
//------------------------------------------------------------------------- void s2cAccountResponse(AccountResponse account_response) { switch (account_response.id) { case AccountResponseId.EnterWorld: // 进入游戏世界 { var enterworld_response = EbTool.protobufDeserialize <ClientEnterWorldResponse>(account_response.data); if (enterworld_response == null || enterworld_response.result != ProtocolResult.Success || enterworld_response.et_player_data == null || string.IsNullOrEmpty(enterworld_response.et_player_data.entity_guid)) { // 进入游戏世界失败,则断开连接 string s = "进入游戏世界失败"; if (enterworld_response != null) { s = string.Format("进入游戏世界失败,ErrorCode={0}", enterworld_response.result); } //FloatMsgInfo f_info; //f_info.msg = s; //f_info.color = Color.red; //UiMgr.Instance.FloatMsgMgr.createFloatMsg(f_info); disconnect(); } else { // 进入游戏世界成功 //FloatMsgInfo f_info; //f_info.msg = "进入游戏世界成功"; //f_info.color = Color.green; //UiMgr.Instance.FloatMsgMgr.createFloatMsg(f_info); Entity et_player = EntityMgr.createEntityByData <EtPlayer>( enterworld_response.et_player_data, CoApp.Entity); } } break; default: break; } }
//------------------------------------------------------------------------- // 客户端断开连接 public async Task c2sClientDeattach() { EbLog.Note("CellPlayer.c2sClientDeattach() EtGuid=" + Entity.Guid); CachePlayerData.player_server_state = PlayerServerState.Offline; // 通知PlayerProxy,玩家离线 var grain = Entity.getUserData <GrainCellPlayer>(); var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(Entity.Guid)); grain_playerproxy.s2sPlayerServerStateChange(CachePlayerData.player_server_state); string data = EbTool.jsonSerialize(CachePlayerData); //DbClientCouchbase.Instance.asyncSave(CachePlayerKey, data, TimeSpan.FromSeconds(15.0)); await CoPlayerDesktop.leaveDesktop(); }
static int _m_checkCidInfo_xlua_st_(RealStatePtr L) { try { { string _cid = LuaAPI.lua_tostring(L, 1); string gen_ret = EbTool.checkCidInfo(_cid); LuaAPI.lua_pushstring(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
//--------------------------------------------------------------------- // 桌子内聊天广播 public Task s2sDesktopChat(ChatMsgRecv msg) { DesktopNotify desktop_notify; desktop_notify.id = DesktopNotifyId.PlayerChat; desktop_notify.data = EbTool.protobufSerialize <ChatMsgRecv>(msg); StreamData sd = new StreamData(); sd.event_id = StreamEventId.DesktopStreamEvent; sd.param1 = desktop_notify; var grain_desktop = Entity.getUserData <GrainCellDesktop>(); grain_desktop.AsyncStream.OnNextAsync(sd); return(TaskDone.Done); }
public void TestProtoBufSerializerProp() { TestData1 test_data1 = new TestData1(); test_data1.s1 = "aaa"; test_data1.s2 = "asdfasdfasdfasdf"; test_data1.a1 = 1100; test_data1.a2 = 5000; MemoryStream s = new MemoryStream(); var buf = EbTool.protobufSerialize(s, test_data1); var test_data2 = EbTool.protobufDeserialize <TestData1>(s, buf); int aa = 0; //Prop<int> p = new Prop<int>(); //p.Key = "aaa"; //p.set(100); //Dictionary<string, IProp> m = new Dictionary<string, IProp>(); //m[p.Key] = p; //byte[] data = null; //using (MemoryStream s = new MemoryStream()) //{ // ProtoBuf.Serializer.Serialize<Dictionary<string, IProp>>(s, m); // data = s.ToArray(); //} //using (MemoryStream s = new MemoryStream(data)) //{ // var m1 = ProtoBuf.Serializer.Deserialize<Dictionary<string, IProp>>(s); // IProp p1 = m1["aaa"]; // Prop<int> p2 = new Prop<int>(); // p2.copyValueFrom(p1); // Debug.WriteLine(p1.Key); // Debug.WriteLine(p1.getValue()); // Debug.WriteLine(p2.Key); // Debug.WriteLine(p2.getValue()); //} }