public ConcurrentRPC(RPCService rpc, int accountId) { RPC = rpc; AccountId = accountId; AggregatedStatistics = new AggregatedStats[StatisticsService.Seasons]; }
public void Close() { MyLogger.Log(LOG_TAG_MAIN, "Close()"); isRunning = false; if (mGame != null) { mGame.Dispose(); mGame = null; } if (mRoom != null) { mRoom.Dispose(); mRoom = null; mRoomRPC = null; } if (mGameSocket != null) { mGameSocket.Dispose(); mGameSocket = null; } if (mThreadMain != null) { mThreadMain.Interrupt(); mThreadMain = null; } DelAllSession(); }
public void Close() { Debuger.Log(LOG_TAG_MAIN, "Close()"); m_IsRunning = false; if (m_Game != null) { m_Game.Dispose(); m_Game = null; } if (m_Room != null) { m_Room.Dispose(); m_Room = null; m_RoomRPC = null; } if (m_GameSocket != null) { m_GameSocket.Dispose(); m_GameSocket = null; } if (m_ThreadMain != null) { m_ThreadMain.Interrupt(); m_ThreadMain = null; } DelAllSession(); }
public static async Task <List <Emote> > GetEmotes() { List <Emote> allEmotes = await RPCService.Invoke <List <Emote> >("EmoteService.GetEmotes"); ////allEmotes.Sort((Emote a, Emote b) => ////{ //// return a.Name.CompareTo(b.Name); ////}); return(allEmotes); }
//------------------------------------------------------------ #region 启动 public bool Start(int port) { if (m_IsRunning) { Debuger.LogWarning(LOG_TAG_MAIN, "Start() 不能重复创建启动Server!"); return(false); } Debuger.Log(LOG_TAG_MAIN, "Start() port = {0}", port); DelAllSession(); try { m_LogicLastTicks = DateTime.Now.Ticks; m_RealTicksAtStart = m_LogicLastTicks; //创建Game Socket m_GameSocket = new KCPSocket(0, 1); m_GameSocket.AddReceiveListener(OnReceive); m_IsRunning = true; //一个简单通用的房间模块 m_Room = new FSPRoom(); m_Room.Create(); m_RoomRPC = m_Room; //创建线程 Debuger.Log(LOG_TAG_MAIN, "Start() 创建服务器线程"); m_ThreadMain = new Thread(Thread_Main) { IsBackground = true }; m_ThreadMain.Start(); } catch (Exception e) { Debuger.LogError(LOG_TAG_MAIN, "Start() " + e.Message); Close(); return(false); } //当用户直接用UnityEditor上的停止按钮退出游戏时,会来不及走完整的析构流程。 //这里做一个监听保护 #if UNITY_EDITOR UnityEditor.EditorApplication.playmodeStateChanged -= OnEditorPlayModeChanged; UnityEditor.EditorApplication.playmodeStateChanged += OnEditorPlayModeChanged; #endif return(true); }
//------------------------------------------------------------ #region start server public bool Start(int port) { if (isRunning) { MyLogger.LogWarning(LOG_TAG_MAIN, "Start()", "cannot start duplicated Server!"); return(false); } MyLogger.Log(LOG_TAG_MAIN, "Start() port = {0}", port.ToString()); DelAllSession(); try { mLogicLastTicks = DateTime.Now.Ticks; mRealTicksAtStart = mLogicLastTicks; //create Game Socket mGameSocket = new KCPSocket(0, 1); mGameSocket.AddReceiveListener(OnReceive); isRunning = true; //create game room mRoom = new FSPRoom(); mRoom.Create(); mRoomRPC = mRoom; //create thread MyLogger.Log(LOG_TAG_MAIN, "Start() create server thead"); mThreadMain = new Thread(Thread_Main) { IsBackground = true }; mThreadMain.Start(); } catch (Exception e) { MyLogger.LogError(LOG_TAG_MAIN, "Start() ", e.Message); Close(); return(false); } //when user exit the game using stop button in UnityEditor, cannot release all resource in time //add listener here #if UNITY_EDITOR UnityEditor.EditorApplication.playmodeStateChanged -= OnEditorPlayModeChanged; UnityEditor.EditorApplication.playmodeStateChanged += OnEditorPlayModeChanged; #endif return(true); }
public static async Task <List <Role> > GetRoles() { List <Role> allRoles = await RPCService.Invoke <List <Role> >("GuildService.GetRoles"); List <Role> roles = new List <Role>(); foreach (Role role in allRoles) { roles.Add(role); } roles.Sort((Role a, Role b) => { return(a.Name.CompareTo(b.Name)); }); return(roles); }
public static async Task Authenticate(string code, string url) { data = await RPCService.Invoke <Data>("AuthenticationService.AuthenticateCode", url, code); if (data == null) { throw new Exception("Authentication failed"); } if (string.IsNullOrEmpty(data.AuthToken)) { throw new Exception("Invalid token"); } if (data.Guilds == null || data.Guilds.Count <= 0) { throw new Exception("You must be in at least one guild"); } Console.WriteLine(">> User has " + data.Guilds.Count + " guilds"); // set the first available guild as the default foreach (Data.Guild guild in data.Guilds) { if (!guild.CanManageGuild) { continue; } RPCService.GuildId = guild.GetId(); RPCService.CanManageGuild = guild.CanManageGuild; break; } if (RPCService.GuildId == 0) { // Set to first Data.Guild defaultGuild = data.Guilds.GetFirst(); RPCService.GuildId = defaultGuild.GetId(); RPCService.CanManageGuild = defaultGuild.CanManageGuild; } }
void Connect() { //Obtain a lock on the profile to avoid race conditions while the user is editing the data lock (Profile) { if (Profile.Login == null) { //The user has removed the login for this worker after the worker had been previously connecting - cancel WriteLine("No login specified"); return; } else { ConnectionProfile connectionData = new ConnectionProfile(AuthenticationProfile, Profile.Region, Configuration.Proxy, Profile.Login.Username.ToLower(), Profile.Login.Password); RPC = new RPCService(connectionData, OnConnect, OnDisconnect); WriteLine("Connecting to the server"); } } RPC.Connect(); }
public static async Task <List <Channel> > GetChannels(Channel.Types type = Channel.Types.Text) { List <Channel> allChanels = await RPCService.Invoke <List <Channel> >("GuildService.GetChannels"); List <Channel> channels = new List <Channel>(); foreach (Channel channel in allChanels) { if (channel.Type != type) { continue; } channels.Add(channel); } channels.Sort((Channel a, Channel b) => { return(a.Name.CompareTo(b.Name)); }); return(channels); }
public ServiceBase() { RPCService.BindMethods(this); }
public ConcurrentRPC(RPCService rpc, int accountId) { RPC = rpc; AccountId = accountId; }
void Connect() { RPC = new RPCService(ConnectionData, OnConnect, OnDisconnect, OnNetStatus); RPC.Connect(); }