コード例 #1
0
        /// Callback Déconnexion du serveur
        /// </summary>
        /// <param name="asyncResult"></param>
        private void DisconnectCB(HttpWebResponse Response)
        {
            if (m_btnConnect != null)
            {
                m_btnConnect.Invoke(new Action(() =>
                {
                    m_btnConnect.Enabled = true;;
                }));
            }
            XmlDocument xmlDoc = null;

            if (Response != null)
            {
                xmlDoc = GetResultXml(ref Response);
                Response.Close();
            }
            m_bConnected   = false;
            m_SyncAIDone   = false;
            m_AIManagement = false;
            Key            = "";
            Log.LogMessage("Déconnecté du serveur");
            m_btnConnect.Invoke(new Action(() =>
            {
                m_btnConnect.ImageIndex = 0;
                ButtonsTips.SetToolTip(m_btnConnect, "Connexion au serveur");
                P2P.Clear();
                if (DelayedExit)
                {
                    System.Windows.Forms.Application.Exit();
                    DelayedExit = false;
                }
                else if (DelayReco)
                {
                    m_btnConnect.Invoke(new Action(() => { m_btnConnect.PerformClick(); }));
                    DelayReco = false;
                }
            }));
        }
コード例 #2
0
        /// <summary>
        /// Callback Demande de connexion
        /// </summary>
        /// <param name="asyncResult"></param>
        private void ConnectCB(HttpWebResponse Response)
        {
            if (m_btnConnect != null)
            {
                m_btnConnect.Invoke(new Action(() =>
                {
                    m_btnConnect.Enabled = true;;
                }));
            }
            XmlDocument xmlDoc = null;

            if (Response != null)
            {
                if (Response.StatusCode != HttpStatusCode.OK)
                {
                    Log.LogMessage("Erreur de connexion : " + Response.StatusDescription, Color.DarkViolet);
                }
                xmlDoc = GetResultXml(ref Response);
                Response.Close();
            }
            if (xmlDoc == null)
            {
                Log.LogMessage("Erreur de connexion", Color.DarkViolet);
                return;
            }
            bool    bError = CheckError(xmlDoc);
            XmlNode Node   = GetFirstElement(ref xmlDoc, "loginStatus");

            if (Node != null)
            {
                if (Node.InnerText == "1")
                {
                    m_bConnected = true;
                }
                else
                {
                    m_bConnected = false;
                }
                if (m_bConnected && (!bError))
                {
                    Log.LogMessage("ffs2play est connecté au serveur");
                    XmlNode xmlExternalIP = GetFirstElement(ref xmlDoc, "your_ip");
                    if (xmlExternalIP != null)
                    {
                        IPAddress ExternalIP = IPAddress.Parse("0.0.0.0");
                        if (IPAddress.TryParse(xmlExternalIP.InnerText, out ExternalIP))
                        {
#if DEBUG
                            Log.LogMessage("PManager: Reçu IP Exterieure = " + ExternalIP.ToString(), Color.DarkBlue, 2);
#endif
                        }
                        else
                        {
#if DEBUG
                            Log.LogMessage("PManager: Reçu IP Exterieure invalide", Color.DarkViolet, 2);
#endif
                        }
                        P2P.ExternalIP = ExternalIP;
                    }
                    else
                    {
                        Log.LogMessage("Le serveur n'a pas retourné votre IP extérieure");
                        m_bConnected = false;
                        return;
                    }

                    XmlNode xmlKey = GetFirstElement(ref xmlDoc, "key");
                    if (xmlKey != null)
                    {
                        Key = xmlKey.InnerText;
                        OnLiveUpdate(null, null);
                    }
                    else
                    {
                        Log.LogMessage("Le serveur n'a pas retourné de clé d'authentification");
                    }

                    XmlNode xmlAtc = GetFirstElement(ref xmlDoc, "atc");
                    if (xmlAtc != null)
                    {
                        if (xmlAtc.InnerText != "")
                        {
                            if (Convert.ToBoolean(xmlAtc.InnerText))
                            {
                                ATCTimer.Start();
                            }
                        }
                    }

                    XmlNode AIManagement = GetFirstElement(ref xmlDoc, "AI_Management");
                    if (AIManagement != null)
                    {
                        if (AIManagement.InnerText != "")
                        {
                            m_AIManagement = Convert.ToBoolean(AIManagement.InnerText);
                        }
                    }

                    // Passage du fond du bouton en vert
                    m_btnConnect.Invoke(new Action(() =>
                    {
                        m_btnConnect.ImageIndex = 1;
                        ButtonsTips.SetToolTip(m_btnConnect, "Déconnexion du serveur");
                    }));
                    // On charge la liste des joueurs depuis le wazzup
                    XmlNode Wazzup = GetFirstElement(ref xmlDoc, "whazzup");
                    if (Wazzup != null)
                    {
                        P2P.Wazzup_Update(Wazzup, m_sAESKey);
                    }
                }
                else
                {
                    Log.LogMessage("Le serveur a refusé la connexion");
                    return;
                }
            }
        }