예제 #1
0
 protected override void OnPeerConnected(IPeer peer)
 {
     try
     {
         // join game after connected
         if (game != null)
         {
             if (game.status == GameStatus.WaitToInitialize)
             {
                 debugger.Log("Start initialize game.");
                 game.Initialize().Wait();
                 debugger.Log("End initialize game.");
             }
             if (game.status == GameStatus.WaitToStart)
             {
                 debugger.Log("Start game.");
                 game.Start();
             }
         }
         debugger.Log("Join game.");
         game.JoinAsync(peer, null)
         .ContinueWith((res) => OnPeerJoinResponse(peer, res.Result));
     }
     catch (Exception e)
     {
         debugger.LogError(e);
     }
 }
예제 #2
0
 public void ResetServer()
 {
     if (server == null)
     {
         //server = new UnityServer(debugger);
         ProcessServer ps = new ProcessServer();
         ps.OnReceiveOutput += (sender, args) =>
         {
             debugger.Log(args.Data);
         };
         server = ps;
     }
     server.Reset();
 }
예제 #3
0
 public void Start()
 {
     debugger.Log("Launching server ... ");
     server.ConnectKey = ConnectKey;
     server.MaxPeers   = MaxPeers;
     server.Start(Port);
 }
예제 #4
0
 /// <summary>
 /// 打印
 /// </summary>
 /// <param name="message">消息</param>
 /// <param name="color">颜色</param>
 public void Log(object message, string color = "white")
 {
     if (!HasLevel(DebugLevel.Normal))
     {
         return;
     }
     debugger.Log(message, color);
 }
    private void OnClientReceivePacketEvent(object obj, Reliability reliability)
    {
        GenericPacket packet = obj as GenericPacket;

        if (packet != null)
        {
            if (receivers.TryGetValue(packet.InstCode, out List <IPacketReceiver> receiverList))
            {
                try
                {
                    foreach (var receiver in receiverList)
                    {
                        receiver.Receive(packet.Data);
                    }
                }
                catch (Exception e)
                {
                    debugger.LogError(e.Message + e.StackTrace);
                }
            }
            if (actions.TryGetValue(packet.InstCode, out List <Action <object> > actionList))
            {
                foreach (var action in actionList)
                {
                    try
                    {
                        action.Invoke(packet.Data);
                    }
                    catch (Exception e)
                    {
                        debugger.Log(e.Message + e.StackTrace);
                    }
                }
            }
        }
        else
        {
            debugger.Log("Packet is null.");
        }
    }
예제 #6
0
        public void ExitAll(string msg = "", object arg = null)
        {
            // cancel all of queuing requests
            int queueingCount =
                CancelAllRequestFromList(ref joinQueuing, msg, arg);
            // cancel all of handling requests
            int handlingCount =
                CancelAllRequestFromList(ref joinHandling, msg, arg);

            int inGroupCount = peers.Count;
            // untrack current group from peers
            List <IPeer> inGroups = new List <IPeer>(peers.Values);

            // clear all peers
            peers.Clear();
            foreach (var peer in inGroups)
            {
                peer.UntrackGroup(this);
            }
            debugger.Log($"Group[{GroupId}] exit all peers, queueing cancelled : {queueingCount}, handling cancelled : {handlingCount}, in group : {inGroupCount}");
        }
예제 #7
0
 /// <summary>
 /// 以同步的形式加载指定的资源
 /// </summary>
 /// <param name="path">资源路径</param>
 protected override object InternalLoadSync(string path)
 {
     debugger.Log("LoaderAssetBundle : " + path);
     return("LoaderAssetBundle");
 }
 public void Log(object obj)
 {
     Debugger.Log(obj);
 }
예제 #9
0
 public static void Log(byte[] bytes)
 {
     Debugger.Log(bytes);
 }
 /// <summary>
 /// 以同步的形式加载指定的资源
 /// </summary>
 /// <param name="path">资源路径</param>
 protected override object InternalLoadSync(string path)
 {
     debugger.Log("LoaderResourcesFolder : " + path);
     return("LoaderResourcesFolder");
 }