Exemplo n.º 1
0
 internal SoraConnectionInfo(Guid serviceId, ISoraSocket connection,
                             DateTime lastHeartBeatTime, TimeSpan apiTimeout)
 {
     ServiceId         = serviceId;
     Connection        = connection;
     LastHeartBeatTime = lastHeartBeatTime;
     SelfId            = 0;
     ApiTimeout        = apiTimeout;
 }
Exemplo n.º 2
0
 /// <summary>
 /// 添加服务器连接记录
 /// </summary>
 /// <param name="serviceId">服务Id</param>
 /// <param name="connectionId">连接标识</param>
 /// <param name="socket">连接信息</param>
 /// <param name="apiTimeout">api超时</param>
 private static bool AddConnection(Guid serviceId, Guid connectionId, ISoraSocket socket,
                                   TimeSpan apiTimeout)
 {
     //检查是否已存在值
     if (StaticVariable.ConnectionInfos.ContainsKey(connectionId))
     {
         return(false);
     }
     //selfId均在第一次链接开启时留空,并在meta事件触发后更新
     return(StaticVariable.ConnectionInfos.TryAdd(connectionId, new SoraConnectionInfo
                                                      (serviceId,
                                                      socket,
                                                      DateTime.Now,
                                                      apiTimeout
                                                      )));
 }
Exemplo n.º 3
0
    /// <summary>
    /// 服务器链接开启事件
    /// </summary>
    /// <param name="role">通道标识</param>
    /// <param name="selfId">事件源</param>
    /// <param name="socket">连接</param>
    /// <param name="serviceId">服务ID</param>
    /// <param name="connId">连接ID</param>
    /// <param name="apiTimeout">api超时</param>
    internal void OpenConnection(string role, string selfId, ISoraSocket socket, Guid serviceId, Guid connId,
                                 TimeSpan apiTimeout)
    {
        //添加服务器记录
        if (!AddConnection(serviceId, connId, socket, apiTimeout))
        {
            //记录添加失败关闭超时的连接
            socket.Close();
            Log.Error("ConnectionManager", $"Cannot record connection[{connId}]");
            return;
        }

        if (OnOpenConnectionAsync == null)
        {
            return;
        }
        if (!long.TryParse(selfId, out long uid))
        {
            Log.Error("ConnectionManager", "非法selfid,已忽略");
        }
        Task.Run(async() => { await OnOpenConnectionAsync(connId, new ConnectionEventArgs(role, uid)); });
    }