//--------------------------------------------------------------------- public override bool openDb(string db_name, Stream stream) { if (sqlite3_open(mFilePath, out connection) != SQLITE_OK) { EbLog.Note("Could not open database file:" + mFilePath); return(false); } return(true); }
//------------------------------------------------------------------------- void _onUCenterRegister(UCenterResponseStatus status, AccountRegisterResponse response, UCenterError error) { EbLog.Note("ClientSampleApp._onUCenterRegister() UCenterResult=" + status); if (error != null) { EbLog.Note("ErrorCode=" + error.ErrorCode); EbLog.Note("ErrorMessage=" + error.Message); } }
//------------------------------------------------------------------------- // 好友通知 void s2cPlayerFriendNotify(PlayerFriendNotify playerfriend_notify) { switch (playerfriend_notify.id) { case PlayerFriendNotifyId.RecommendPlayerList: // 推荐好友列表 { //EbLog.Note("ClientPlayerFriend.s2cPlayerFriendNotify() RecommendPlayerList"); var list_recommend = EbTool.protobufDeserialize <List <PlayerInfo> >(playerfriend_notify.data); var e = EntityMgr.getDefaultEventPublisher().genEvent <EvEntityRecommendPlayerList>(); e.list_recommend = list_recommend; e.send(null); } break; case PlayerFriendNotifyId.AddFriend: // 通知添加好友 { EbLog.Note("ClientPlayerFriend.s2cPlayerFriendNotify() AddFriend"); var friend_item = EbTool.protobufDeserialize <PlayerInfo>(playerfriend_notify.data); Dictionary <string, PlayerInfo> map_friend = Def.mPropMapFriend.get(); map_friend[friend_item.player_etguid] = friend_item; var e = EntityMgr.getDefaultEventPublisher().genEvent <EvEntityNotifyAddFriend>(); e.friend_item = friend_item; e.send(null); } break; case PlayerFriendNotifyId.DeleteFriend: // 通知删除好友 { EbLog.Note("ClientPlayerFriend.s2cPlayerFriendNotify() DeleteFriend"); var friend_etguid = EbTool.protobufDeserialize <string>(playerfriend_notify.data); PlayerInfo friend = null; Dictionary <string, PlayerInfo> map_friend = Def.mPropMapFriend.get(); if (map_friend.TryGetValue(friend_etguid, out friend)) { map_friend.Remove(friend_etguid); } var e = EntityMgr.getDefaultEventPublisher().genEvent <EvEntityNotifyDeleteFriend>(); e.friend_etguid = friend_etguid; e.send(null); } break; default: break; } }
//--------------------------------------------------------------------- public override void init() { EbLog.Note("EsApp.init() entity_rpcid=" + Entity.getEntityRpcId()); defRpcMethod((byte)_eNodeType.Ec, (ushort)_eMethodType.ec2esLogin, ec2esLogin); //EntityMgr.defRpcMethod((byte)_eNodeType.Ec, (ushort)_eMethodType.nodeEc2EsLogin, nodeEc2EsLogin); EnableUpdate = true; Def.mPropNickName.set("test_nickname"); }
//------------------------------------------------------------------------- void _onSocketConnected(object client, EventArgs args) { EbLog.Note("ClientSampleNetwork._onSocketConnected()"); //rpc(MethodType.c2sAccountRequest, account_request); DefaultRpcSession.rpc(999); //byte[] data = Encoding.UTF8.GetBytes("Hello world"); //if (session != null) session.send(method_id, data); }
//------------------------------------------------------------------------- public override void init() { EbLog.Note("ClientUCenterSession.init()"); defRpcMethod((byte)_eUCenterNodeType.UCenter, (ushort)_eUCenterMethodType.login2ClientOnLogin, login2ClientOnLogin); // 设置session RpcSession session = (RpcSession)Entity.getCacheData("RemoteSession"); Entity.setSession((byte)_eUCenterNodeType.UCenter, session); }
//------------------------------------------------------------------------- // 请求交付任务 public void requestFinishTask(int task_id) { EbLog.Note("ClientPlayerTask.requestFinishTask() TaskId=" + task_id); PlayerTaskRequest playertask_request; playertask_request.id = PlayerTaskRequestId.TaskFinish; playertask_request.data = EbTool.protobufSerialize <int>(task_id); DefaultRpcSession.rpc((ushort)MethodType.c2sPlayerTaskRequest, playertask_request); }
//--------------------------------------------------------------------- public override void init() { EbLog.Note("EcApp.init() entity_rpcid=" + Entity.getEntityRpcId()); defRpcMethod((byte)_eNodeType.Es, (ushort)_eMethodType.es2ecOnLogin, es2ecOnLogin); mPeer = new PhotonClientPeer(EntityMgr, 1, (RpcSessionListener)this); Entity.setSession((byte)_eNodeType.Es, mPeer.getRpcSession()); mPeer.Connect("127.0.0.1:5880", "EsTest"); }
//------------------------------------------------------------------------- public void playBackgroundSound(string snd_name, bool is_loop = false) { if (string.IsNullOrEmpty(snd_name)) { EbLog.Note("ClientSound.playBackgroundSound() 声音名称为空"); } string full_snd_name = "Audio/" + snd_name; AudioClip audio_clip = (AudioClip)Resources.Load(full_snd_name, typeof(AudioClip)); //SoundManager.Play(audio_clip, is_loop); }
//------------------------------------------------------------------------- public async Task <MethodData> c2sPlayerLobbyRequest(MethodData method_data) { MethodData result = new MethodData(); result.method_id = MethodType.None; var lobby_request = EbTool.protobufDeserialize <PlayerLobbyRequest>(method_data.param1); switch (lobby_request.id) { case PlayerLobbyRequestId.SearchDesktop: // 搜索桌子 { EbLog.Note("CellPlayerLobby.c2sPlayerLobbyRequest() SearchDesktop"); var search_filter = EbTool.protobufDeserialize <DesktopSearchFilter>(lobby_request.data); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_desktopservice = grain.GF.GetGrain <ICellDesktopService>(0); var list_desktop_info = await grain_desktopservice.searchDesktop(search_filter); PlayerLobbyResponse lobby_response; lobby_response.id = PlayerLobbyResponseId.SearchDesktop; lobby_response.data = EbTool.protobufSerialize <List <DesktopInfo> >(list_desktop_info); result.method_id = MethodType.s2cPlayerLobbyResponse; result.param1 = EbTool.protobufSerialize <PlayerLobbyResponse>(lobby_response); } break; case PlayerLobbyRequestId.SearchDesktopFollowFriend: // 搜索好友所在的牌桌 { EbLog.Note("CellPlayerLobby.c2sPlayerLobbyRequest() SearchDesktopFollowFriend"); var desktop_etguid = EbTool.protobufDeserialize <string>(lobby_request.data); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_desktopservice = grain.GF.GetGrain <ICellDesktopService>(0); var list_desktop_info = await grain_desktopservice.searchDesktopFollowFriend(desktop_etguid); PlayerLobbyResponse lobby_response; lobby_response.id = PlayerLobbyResponseId.SearchDesktopFollowFriend; lobby_response.data = EbTool.protobufSerialize <List <DesktopInfo> >(list_desktop_info); result.method_id = MethodType.s2cPlayerLobbyResponse; result.param1 = EbTool.protobufSerialize <PlayerLobbyResponse>(lobby_response); } break; default: break; } return(result); }
//--------------------------------------------------------------------- public void onPlayerActionWaitingTimeEnd(string player_etguid) { SeatInfo seat_cur = getSeat(player_etguid); if (seat_cur == null) { return; } EbLog.Note("CellDesktop.onPlayerActionWaitingTimeEnd() PlayerEtGuid=" + player_etguid); }
//------------------------------------------------------------------------- void _onSocketError(object rec, SocketErrorEventArgs args) { EbLog.Note("ClientNetMonitor._onSocketError()"); //FloatMsgInfo f_info; //f_info.msg = "连接已断开!"; //f_info.color = Color.red; //UiMgr.Instance.FloatMsgMgr.createFloatMsg(f_info); _onSocketClose(); }
//------------------------------------------------------------------------- void Start() { // 初始化系统参数 { Application.runInBackground = true; Time.fixedDeltaTime = 0.03f; Application.targetFrameRate = 60; Screen.sleepTimeout = SleepTimeout.NeverSleep; } // 初始化日志 { EbLog.NoteCallback = Debug.Log; EbLog.WarningCallback = Debug.LogWarning; EbLog.ErrorCallback = Debug.LogError; } EbLog.Note("MbMain.Start()"); // 初始化PathMgr if (mPathMgr == null) { mPathMgr = new PathMgr(); } if (mClientConfig == null) { mClientConfig = new ClientConfig(); } if (mAsyncLoadAssetMgr == null) { mAsyncLoadAssetMgr = new AsyncLoadAssetMgr(); mAsyncLoadAssetMgr.init(); } if (mEngine == null) { EcEngineSettings settings; settings.ProjectName = "Fishing"; settings.RootEntityType = "EtRoot"; settings.EnableCoSuperSocket = true; mEngine = new EcEngine(ref settings, new EcEngineListener()); } UiMgr = new UiMgr(); UiMgr.create(EntityMgr.Instance); mSoundMgr = new CSoundMgr(); // 创建EtClientApp EntityMgr.Instance.createEntity <EtApp>(null, EcEngine.Instance.EtNode); }
//------------------------------------------------------------------------- // Print usage info to console window, showing cmd-line params for OrleansHost.exe public void PrintUsage() { EbLog.Note( @"USAGE: OrleansHost.exe [<siloName> [<configFile>]] [DeploymentId=<idString>] [/debug] Where: <siloName> - Name of this silo in the Config file list (optional) <configFile> - Path to the Config file to use (optional) DeploymentId=<idString> - Which deployment group this host instance should run in (optional) /debug - Turn on extra debug output during host startup (optional)"); }
//--------------------------------------------------------------------- public void subscribeChildChanges(string path, zkOpeHandler handler = null, Dictionary <string, object> param = null) { if (path != null && path != "" && !_childListener.ContainsKey(path)) { zkHandlerParam hp = new zkHandlerParam(); hp.handler = handler; hp.param = param; _childListener.Add(path, hp); awatchForChilds(path, handler, param); EbLog.Note("Subscribed child changes for:" + path); } }
//--------------------------------------------------------------------- public void close() { if (mConnection == null) { return; } setShutdownTrigger(true); mConnection.close(); mConnection = null; ZK_CONST.Release(); EbLog.Note("Closing ZkClient...done"); }
//--------------------------------------------------------------------- public void subscribeExists(string path, zkOpeHandler handler = null, Dictionary <string, object> param = null) { if (path != null && path != "" && !_existsListener.ContainsKey(path)) { EbLog.Note("Subscribed Exists changes for:" + path); zkHandlerParam hp = new zkHandlerParam(); hp.handler = handler; hp.param = param; _existsListener.Add(path, hp); aexists(path, true, handler, param); } }
//------------------------------------------------------------------------- public override void init() { EbLog.Note("ClientNode.init()"); var settings = EcEngine.Instance.Settings; if (settings.EnableCoSuperSocket) { var et = EntityMgr.createEntity <EtSuperSocket>(null, Entity); CoSuperSocket = et.getComponent <ClientSuperSocket <DefSuperSocket> >(); } }
//--------------------------------------------------------------------- /// <summary> /// This will prepare a certain query where stmHandle is pointing or handling /// </summary> private IntPtr Prepare(string query) { IntPtr stmHandle; if (sqlite3_prepare_v2(connection, query, -1, out stmHandle, IntPtr.Zero) != SQLITE_OK) { IntPtr errorMsg = sqlite3_errmsg(connection); EbLog.Note(Marshal.PtrToStringAnsi(errorMsg) + ":" + query); } return(stmHandle); }
//------------------------------------------------------------------------- //------------------------------------------------------------------------- public override void init() { EbLog.Note("ClientSampleApp.init()"); EntityMgr.getDefaultEventPublisher().addHandler(Entity); // AutoPatcher示例 //EntityMgr.createEntity<EtSampleAutoPatcher>(null, Entity); // Network示例 EntityMgr.createEntity <EtSampleNetwork>(null, Entity); }
//------------------------------------------------------------------------- void _onUCenterLogin(UCenterResponseStatus status, AccountLoginResponse response, UCenterError error) { string s = "ClientSampleApp._onUCenterLogin() UCenterResult=" + status; EbLog.Note(s); MbSample.Instance.ListInfo.Add(s); if (error != null) { EbLog.Note("ErrorCode=" + error.ErrorCode); EbLog.Note("ErrorMessage=" + error.Message); } }
//------------------------------------------------------------------------- // 响应登陆请求 public void client2LoginLogin(RpcSession s, Dictionary <byte, object> map_param) { EbLog.Note("LoginUCenterSession.client2LoginLogin()"); string account = (string)map_param[0]; string password = (string)map_param[1]; string serverGroup = (string)map_param[2]; string channel = (string)map_param[3]; LoginApp <ComponentDef> login = EntityMgr.findFirstEntity("EtApp").getComponent <LoginApp <ComponentDef> >(); login.addLoginPlayer(serverGroup, account, password, channel, this); }
//------------------------------------------------------------------------- public override void init() { EbLog.Note("LoginUCenterSession.init()"); defRpcMethod((byte)_eUCenterNodeType.Client, (ushort)_eUCenterMethodType.client2LoginLogin, client2LoginLogin); // 设置session RpcSession session = (RpcSession)Entity.getCacheData("RemoteSession"); Entity.setSession((byte)_eUCenterNodeType.Client, session); // Create Client Remote rpcOneCreateRemote((byte)_eUCenterNodeType.Client, false); }
//------------------------------------------------------------------------- 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 override void init() { EbLog.Note("ClientPlayerRanking.init()"); defNodeRpcMethod <PlayerRankingResponse>( (ushort)MethodType.s2cPlayerRankingResponse, s2cPlayerRankingResponse); defNodeRpcMethod <PlayerRankingNotify>( (ushort)MethodType.s2cPlayerRankingNotify, s2cPlayerRankingNotify); Entity et_app = EntityMgr.findFirstEntityByType <EtApp>(); CoApp = et_app.getComponent <ClientApp <DefApp> >(); CoPlayer = Entity.getComponent <ClientPlayer <DefPlayer> >(); }
//------------------------------------------------------------------------- static void _buildAssetBundleCompressed(AssetBundleBuild[] arr_abb, string path, BuildTarget target, bool build_all = true) { if (build_all) { //BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, // BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, target); } else { BuildPipeline.BuildAssetBundles(path, arr_abb, BuildAssetBundleOptions.ForceRebuildAssetBundle, target); } EbLog.Note("Build AssetBundle BuildTarget=" + target); }
//------------------------------------------------------------------------- public override void exit() { // 广播NodeStop消息 if (!mNode.getNodeSys().isClient()) { List <object> list_param = new List <object>(); list_param.Add(mNode.getNodeType()); list_param.Add(mNode.getNodeId()); list_param.Add(mNode.getExitId()); mNode._getNodeServerListener().nodeSendMsg((int)_eNodeMsg.NodeLeaveStop, list_param); } EbLog.Note("CNodeStateStop.exit() NodeType=" + mNode.getNodeType() + " NodeId=" + mNode.getNodeId()); }
//------------------------------------------------------------------------- public override void init() { EbLog.Note("ClientPlayerTrade.init()"); DefaultRpcSession.defRpcMethod <PlayerTradeResponse>( (ushort)MethodType.s2cPlayerTradeResponse, s2cPlayerTradeResponse); DefaultRpcSession.defRpcMethod <PlayerTradeNotify>( (ushort)MethodType.s2cPlayerTradeNotify, s2cPlayerTradeNotify); Entity et_app = EntityMgr.findFirstEntityByType <EtApp>(); CoApp = et_app.getComponent <ClientApp <DefApp> >(); CoPlayer = Entity.getComponent <ClientPlayer <DefPlayer> >(); }
//------------------------------------------------------------------------- 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); }
//------------------------------------------------------------------------- void _onUCenterConvert(UCenterResponseStatus status, GuestConvertResponse response, UCenterError error) { EbLog.Note("ClientSampleApp._onUCenterConvert() UCenterResult=" + status); if (error != null) { EbLog.Note("ErrorCode=" + error.ErrorCode); EbLog.Note("ErrorMessage=" + error.Message); } //else //{ // EbLog.Note("AccountId=" + response.AccountId); // EbLog.Note("AccountName=" + response.AccountName); //} }