Esempio n. 1
0
 /// <summary>
 /// Create a new server connection.
 /// </summary>
 /// <param name="in_server">Specify the server where to connect.</param>
 public CedonkeyServerConexion(CServer in_server)
     : base(in_server.IP, in_server.Port, null)
 {
     m_Server=in_server;
     //  m_TimerTimeout.Change(Timeout.Infinite, Timeout.Infinite);
 }
Esempio n. 2
0
 internal void ConnectToServer(string strIP, ushort port)
 {
     if ((port==0)||(port>=IPEndPoint.MaxPort-4)) return;
     CServer server=new CServer(strIP,port);
     server.Connect();
 }
Esempio n. 3
0
 /// <summary>
 /// Connection to server failed.
 /// </summary>
 /// <param name="reason">Reason</param>
 protected override void OnConnectionFail(byte reason)
 {
     if (m_Server!=null)
     {
     m_Server.Connected=false;
     if (!m_Server.DisconectedByUser)
     {
         switch ( (Protocol.ConnectionReason)reason)
         {
         case Protocol.ConnectionReason.CannotConnect:
             m_Server.IncFails((byte)Protocol.ConnectionReason.CannotConnect);
             break;
         case Protocol.ConnectionReason.ClosedConnection:
             m_Server.IncFails((byte)Protocol.ConnectionReason.ClosedConnection);
             break;
         case Protocol.ConnectionReason.NullPacket:
             m_Server.IncFails((byte)Protocol.ConnectionReason.NullPacket);
             break;
         case Protocol.ConnectionReason.NullID:
             m_Server.IncFails((byte)Protocol.ConnectionReason.NullID);
             break;
         case Protocol.ConnectionReason.InvalidHeader:
             m_Server.IncFails((byte)Protocol.ConnectionReason.InvalidHeader);
             break;
         }
     }
     else
     {
         string strreason="";
         switch ( (Protocol.ConnectionReason)reason)
         {
         case Protocol.ConnectionReason.CannotConnect:
             strreason=CKernel.Globalization["SRV_DOWN"];
             break;
         case Protocol.ConnectionReason.ClosedConnection:
             strreason=CKernel.Globalization["SRV_DISCONNECTED"];
             break;
         case Protocol.ConnectionReason.NullPacket:
             strreason=CKernel.Globalization["SRV_FULL"];
             break;
         case Protocol.ConnectionReason.NullID:
             strreason=CKernel.Globalization["SRV_FULL"];
             break;
         case Protocol.ConnectionReason.InvalidHeader:
             strreason=CKernel.Globalization["SRV_FULL"];
             break;
         }
         CLog.Log(Constants.Log.Info,"SRV_NOTCONNECT", m_Server.Name, strreason);
     }
     if (m_Server!=null) m_Server.DisconectedByUser=false; //check !=null again, the server may be deleted
     }
     CloseConnection();
     m_Server=null;
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new ServerList.
 /// </summary>
 public CServersList()
 {
     m_ConnectionIndex=0;
     m_ActiveServer=null;
     m_LastUDPSourceSearch=DateTime.MinValue;
     m_LastPingUDP=DateTime.MinValue;
     m_NextTCPSourcesSearch=DateTime.MaxValue;
     m_UDPSourceSearchFileIndex=0;
     m_TCPSourceSearchFileIndex=0;
     m_SourceSearchServerIndex=0;
     m_ServerPingUDPIndex=0;
     m_TimesshownUDPClosedMessage=0;
     m_lowIDRetryHelper=new CLowIDRetryHelper();
 }
Esempio n. 5
0
 internal static void NewServer(CServer server)
 {
     for (int i=0; i<=InterfaceGateway.Length-1; i++)
     {
     if (CKernel.InterfaceGateway[i]!=null)
     {
         InterfaceGateway[i].SubmitOnNewServer(server);
     }
     }
 }
Esempio n. 6
0
 public void Insert(int index, CServer value)
 {
     InnerList.Insert(index, value);
 }
Esempio n. 7
0
 public void Remove(CServer value)
 {
     InnerList.Remove(value);
 }
Esempio n. 8
0
 public bool Contains(CServer value)
 {
     return InnerList.Contains(value);
 }
Esempio n. 9
0
 public int IndexOf(CServer value)
 {
     return InnerList.IndexOf(value);
 }
Esempio n. 10
0
 /// <summary>
 /// Connect to an specified server.
 /// </summary>
 /// <param name="ip">IP of the server.</param>
 /// <param name="port">Port of the server</param>
 /// <returns>Returns true if connection could be established.</returns>
 public bool ConnectToServer(uint ip, ushort port)
 {
     CServer server=this[ip,port];
     if (server!=null)
     {
     if (m_ActiveServer!=null)
     {
         m_ActiveServer.Disconnect();
         m_ActiveServer=null;
     }
     server.DisconectedByUser=true; //set this flag to true to avoid reconnect to other servers if it fails
     server.Connect();
     return true;
     }
     else
     return false;
 }
Esempio n. 11
0
 /// <summary>
 /// The connection to server failed.
 /// </summary>
 /// <param name="server">server</param>
 /// <param name="reason">reason</param>
 /// <returns></returns>
 public bool ConnectionFailed(CServer server, byte reason)
 {
     lock (this)
     {
     if (server==ActiveServer)
     {
         ActiveServer=null;
         m_FailedConnetions=0;
         m_ConnectionIndex=0;
         CLog.Log(Constants.Log.Info, "SRV_CNN_LOST");
         if (!CKernel.Preferences.GetBool("AutoReconnect"))
             return false;
         else
         {
             m_ConnectToNextServers();
             return false;
         }
     }
     else if (ActiveServer!=null) return false;
     if (m_ConnectionIndex>0)
     {
         m_FailedConnetions++;
         //if (m_FailedConnetions==Protocol.MAX_CONEXIONESPARALELAS)
         m_ConnectToNextServers();
     }
     }
     return true;
 }
Esempio n. 12
0
 /// <summary>
 /// Remove all servers from the list.
 /// </summary>
 public new void Clear()
 {
     if (m_ActiveServer!=null)
     {
     m_ActiveServer.Disconnect();
     m_ActiveServer=null;
     }
     InnerList.Clear();
 }
Esempio n. 13
0
 /// <summary>
 /// Add a server to the list.
 /// </summary>
 /// <param name="ip">IP of the server.</param>
 /// <param name="port">Port of the server.</param>
 /// <returns>The new server.</returns>
 public CServer Add(uint ip, ushort port)
 {
     if ((ip<Protocol.LowIDLimit)||(port==0)||(port>=IPEndPoint.MaxPort-4)) return null;
     if (this[ip,0]==null)
     {
     CServer server=new CServer(ip,port);
     this.Add(server);
     CKernel.NewServer(server);
     return server;
     }
     else
     return null;
 }
Esempio n. 14
0
 public int Add(CServer value)
 {
     return InnerList.Add(value);
 }