Contains data that's sent to heartbeat servers.
Beispiel #1
0
 static void RaiseHeartbeatSentEvent(HeartbeatData heartbeatData, HttpWebResponse response, string text)
 {
     SentEvent.Raise(new HeartbeatSentEventArgs(heartbeatData,
                                                response.Headers,
                                                response.StatusCode,
                                                text));
 }
Beispiel #2
0
        static bool RaiseHeartbeatSendingEvent(HeartbeatData data, Uri uri, bool getServerUri)
        {
            var e = new HeartbeatSendingEventArgs(data, uri, getServerUri);

            SendingEvent.Raise(e);
            return(!e.Cancel);
        }
Beispiel #3
0
 static bool RaiseHeartbeatSendingEvent( HeartbeatData data, Uri uri, bool getServerUri )
 {
     var h = Sending;
     if( h == null ) return true;
     var e = new HeartbeatSendingEventArgs( data, uri, getServerUri );
     h( null, e );
     return !e.Cancel;
 }
Beispiel #4
0
 static void SendMinecraftNetBeat() {
     HeartbeatData data = new HeartbeatData( MinecraftNetUri );
     if( !RaiseHeartbeatSendingEvent( data, MinecraftNetUri, true ) ) {
         return;
     }
     minecraftNetRequest = CreateRequest( data.CreateUri() );
     var state = new HeartbeatRequestState( minecraftNetRequest, data, true );
     minecraftNetRequest.BeginGetResponse( ResponseCallback, state );
 }
Beispiel #5
0
 static void SendMinecraftNetBeat()
 {
     HeartbeatData data = new HeartbeatData( MinecraftNetUri );
     if( !RaiseHeartbeatSendingEvent( data, MinecraftNetUri, true ) ) {
         return;
     }
     HttpWebRequest request = CreateRequest( data.CreateUri() );
     var state = new HeartbeatRequestState( request, data, true );
     request.BeginGetResponse( ResponseCallback, state );
 }
Beispiel #6
0
 static void RaiseHeartbeatSentEvent( HeartbeatData heartbeatData,
     HttpWebResponse response,
     string text)
 {
     var h = Sent;
     if( h != null ) {
         h( null, new HeartbeatSentEventArgs( heartbeatData,
                                              response.Headers,
                                              response.StatusCode,
                                              text ) );
     }
 }
Beispiel #7
0
        static bool RaiseHeartbeatSendingEvent(HeartbeatData heartbeatData)
        {
            var h = Sending;

            if (h == null)
            {
                return(false);
            }
            var e = new HeartbeatSendingEventArgs(heartbeatData);

            h(null, e);
            return(e.Cancel);
        }
Beispiel #8
0
        private static bool RaiseHeartbeatSendingEvent(HeartbeatData data, Uri uri, bool getServerUri)
        {
            var h = Sending;

            if (h == null)
            {
                return(true);
            }
            var e = new HeartbeatSendingEventArgs(data, uri, getServerUri);

            h(null, e);
            return(!e.Cancel);
        }
Beispiel #9
0
        static void SendWoMDirectBeat() {
            HeartbeatData data = new HeartbeatData( WoMDirectUri );

            // we dont want WoM redirecting back to minecraft.net
            data.CustomData["noforward"] = "1";

            if( !RaiseHeartbeatSendingEvent( data, WoMDirectUri, false ) ) {
                return;
            }
            HttpWebRequest request = CreateRequest( data.CreateUri() );
            var state = new HeartbeatRequestState( request, data, false );
            request.BeginGetResponse( ResponseCallback, state );
        }
Beispiel #10
0
        static bool RaiseHeartbeatSendingEvent([NotNull] HeartbeatData data, [NotNull] Uri uri)
        {
            var h = Sending;

            if (h == null)
            {
                return(true);
            }
            var e = new HeartbeatSendingEventArgs(data, uri);

            h(null, e);
            return(!e.Cancel);
        }
Beispiel #11
0
 public HeartbeatRequestState([NotNull] HttpWebRequest request, [NotNull] HeartbeatData data)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     Request = request;
     Data    = data;
 }
Beispiel #12
0
        static void SendMinecraftNetBeat()
        {
            HeartbeatData data = new HeartbeatData(HeartbeatServerUrl);

            if (!RaiseHeartbeatSendingEvent(data, HeartbeatServerUrl))
            {
                return;
            }
            minecraftNetRequest = CreateRequest(data.CreateUri());
            var state = new HeartbeatRequestState(minecraftNetRequest, data);

            minecraftNetRequest.BeginGetResponse(ResponseCallback, state);
        }
Beispiel #13
0
        static void SendClassiCubeBeat()
        {
            HeartbeatData data = new HeartbeatData(ClassiCubeNetUri);

            if (!RaiseHeartbeatSendingEvent(data, ClassiCubeNetUri, true))
            {
                return;
            }
            minecraftNetRequest = CreateRequest(data.CreateUri(Salt2));
            var state = new HeartbeatRequestState(minecraftNetRequest, data, true);

            minecraftNetRequest.BeginGetResponse(ResponseCallback, state);
        }
Beispiel #14
0
        static void SendWoMDirectBeat()
        {
            HeartbeatData data = new HeartbeatData( WoMDirectUri );

            // we dont want WoM redirecting back to minecraft.net
            data.CustomData["noforward"] = "1";

            if( !RaiseHeartbeatSendingEvent( data, WoMDirectUri, false ) ) {
                return;
            }
            HttpWebRequest request = CreateRequest( data.CreateUri() );
            var state = new HeartbeatRequestState( request, data, false );
            request.BeginGetResponse( ResponseCallback, state );
        }
Beispiel #15
0
        static void SendHeartBeat()
        {
            HeartbeatData data = new HeartbeatData(HeartbeatServerUrl);

            if (!RaiseHeartbeatSendingEvent(data, HeartbeatServerUrl))
            {
                return;
            }

            try {
                heartBeatRequest = CreateRequest(data.CreateUri());
            } catch (Exception ex) {
                Logger.Log(LogType.Debug, ex.ToString());
                return;
            }

            var state = new HeartbeatRequestState(heartBeatRequest, data);

            heartBeatRequest.BeginGetResponse(ResponseCallback, state);
        }
Beispiel #16
0
        static void SendWoMDirectBeat()
        {
            HeartbeatData data = new HeartbeatData(WoMDirectUri);

            // we dont want WoM redirecting back to minecraft.net
            data.CustomData["noforward"] = "1";

            // wom description and flags
            data.CustomData["desc"]  = ConfigKey.WoMDirectDescription.GetString();
            data.CustomData["flags"] = ConfigKey.WoMDirectFlags.GetString();

            if (!RaiseHeartbeatSendingEvent(data, WoMDirectUri, false))
            {
                return;
            }
            womDirectRequest = CreateRequest(data.CreateUri());
            var state = new HeartbeatRequestState(womDirectRequest, data, false);

            womDirectRequest.BeginGetResponse(ResponseCallback, state);
        }
Beispiel #17
0
 public HeartbeatRequestState(HttpWebRequest request, HeartbeatData data)
 {
     Request = request;
     Data    = data;
 }
Beispiel #18
0
        static void Beat( SchedulerTask scheduledTask ) {
            if( Server.IsShuttingDown ) return;

            data = new HeartbeatData {
                IsPublic = ConfigKey.IsPublic.GetBool(),
                MaxPlayers = ConfigKey.MaxPlayers.GetInt(),
                PlayerCount = Server.CountPlayers( false ),
                ServerIP = Server.IP,
                Port = Server.Port,
                ProtocolVersion = Config.ProtocolVersion,
                Salt = Server.Salt,
                ServerName = ConfigKey.ServerName.GetString()
            };

            // This needs to be wrapped in try/catch because and exception in an event handler
            // would permanently stop heartbeat sending.
            try {
                if( RaiseHeartbeatSendingEvent( data ) ) {
                    RescheduleHeartbeat();
                    return;
                }
            } catch( Exception ex ) {
                Logger.LogAndReportCrash( "Heartbeat.Sending handler failed", "fCraft", ex, false );
            }

            if( ConfigKey.HeartbeatEnabled.GetBool() ) {
                UriBuilder ub = new UriBuilder( Uri );
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat( "public={0}&max={1}&users={2}&port={3}&version={4}&salt={5}&name={6}",
                                 data.IsPublic,
                                 data.MaxPlayers,
                                 data.PlayerCount,
                                 data.Port,
                                 data.ProtocolVersion,
                                 Uri.EscapeDataString( data.Salt ),
                                 Uri.EscapeDataString( data.ServerName ) );

                foreach( var pair in data.CustomData ) {
                    sb.AppendFormat( "&{0}={1}",
                                     Uri.EscapeDataString( pair.Key ),
                                     Uri.EscapeDataString( pair.Value ) );
                }
                ub.Query = sb.ToString();

                request = (HttpWebRequest)WebRequest.Create( ub.Uri );
                request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint( BindIPEndPointCallback );
                request.Method = "GET";
                request.Timeout = Timeout;
                request.CachePolicy = new HttpRequestCachePolicy( HttpRequestCacheLevel.BypassCache );

                request.BeginGetResponse( ResponseCallback, null );
            } else {
                // If heartbeats are disabled, the data is written to a text file (heartbeatdata.txt)
                const string tempFile = Paths.HeartbeatDataFileName + ".tmp";

                File.WriteAllLines( tempFile,
                    new[]{
                        Server.Salt,
                        Server.IP.ToString(),
                        Server.Port.ToString(),
                        Server.CountPlayers(false).ToString(),
                        ConfigKey.MaxPlayers.GetString(),
                        ConfigKey.ServerName.GetString(),
                        ConfigKey.IsPublic.GetString()
                    },
                    Encoding.ASCII );

                Paths.MoveOrReplace( tempFile, Paths.HeartbeatDataFileName );
                RescheduleHeartbeat();
            }
        }
Beispiel #19
0
 static bool RaiseHeartbeatSendingEvent( HeartbeatData heartbeatData ) {
     var h = Sending;
     if( h == null ) return false;
     var e = new HeartbeatSendingEventArgs( heartbeatData );
     h( null, e );
     return e.Cancel;
 }
Beispiel #20
0
        static void SendWoMDirectBeat() {
            HeartbeatData data = new HeartbeatData( WoMDirectUri );

            // we dont want WoM redirecting back to minecraft.net
            data.CustomData["noforward"] = "1";

            // wom description and flags
            data.CustomData["desc"] = ConfigKey.WoMDirectDescription.GetString();
            data.CustomData["flags"] = ConfigKey.WoMDirectFlags.GetString();

            if( !RaiseHeartbeatSendingEvent( data, WoMDirectUri, false ) ) {
                return;
            }
            womDirectRequest = CreateRequest( data.CreateUri() );
            var state = new HeartbeatRequestState( womDirectRequest, data, false );
            womDirectRequest.BeginGetResponse( ResponseCallback, state );
        }
Beispiel #21
0
 static void RaiseHeartbeatSentEvent( HeartbeatData heartbeatData, HttpWebResponse response, string text ) {
     SentEvent.Raise( new HeartbeatSentEventArgs( heartbeatData,
                                                  response.Headers,
                                                  response.StatusCode,
                                                  text ) );
 }
Beispiel #22
0
 static void RaiseHeartbeatSentEvent( HeartbeatData heartbeatData,
                                      HttpWebResponse response,
                                      string text ) {
     var h = Sent;
     if( h != null ) {
         h( null, new HeartbeatSentEventArgs( heartbeatData,
                                              response.Headers,
                                              response.StatusCode,
                                              text ) );
     }
 }
Beispiel #23
0
 static void SendHeartBeat()
 {
     HeartbeatData data = new HeartbeatData(HeartbeatServerUrl);
     if (!RaiseHeartbeatSendingEvent(data, HeartbeatServerUrl))
     {
         return;
     }
     try {
         heartBeatRequest = CreateRequest(data.CreateUri());
         } catch (Exception UriFormatException) {
             Logger.Log(LogType.Debug, UriFormatException.ToString());
             return;
         }
     var state = new HeartbeatRequestState(heartBeatRequest, data);
     heartBeatRequest.BeginGetResponse(ResponseCallback, state);
     
 }
Beispiel #24
0
 public HeartbeatRequestState( HttpWebRequest request, HeartbeatData data ) {
     Request = request;
     Data = data;
 }
Beispiel #25
0
        static void Beat(SchedulerTask scheduledTask)
        {
            if (Server.IsShuttingDown)
            {
                return;
            }

            data = new HeartbeatData {
                IsPublic        = ConfigKey.IsPublic.GetBool(),
                MaxPlayers      = ConfigKey.MaxPlayers.GetInt(),
                PlayerCount     = Server.CountPlayers(false),
                ServerIP        = Server.IP,
                Port            = Server.Port,
                ProtocolVersion = Config.ProtocolVersion,
                Salt            = Server.Salt,
                ServerName      = ConfigKey.ServerName.GetString()
            };

            // This needs to be wrapped in try/catch because and exception in an event handler
            // would permanently stop heartbeat sending.
            try {
                if (RaiseHeartbeatSendingEvent(data))
                {
                    RescheduleHeartbeat();
                    return;
                }
            } catch (Exception ex) {
                Logger.LogAndReportCrash("Heartbeat.Sending handler failed", "fCraft", ex, false);
            }

            if (ConfigKey.HeartbeatEnabled.GetBool())
            {
                UriBuilder    ub = new UriBuilder(Uri);
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("public={0}&max={1}&users={2}&port={3}&version={4}&salt={5}&name={6}",
                                data.IsPublic,
                                data.MaxPlayers,
                                data.PlayerCount,
                                data.Port,
                                data.ProtocolVersion,
                                Uri.EscapeDataString(data.Salt),
                                Uri.EscapeDataString(data.ServerName));

                foreach (var pair in data.CustomData)
                {
                    sb.AppendFormat("&{0}={1}",
                                    Uri.EscapeDataString(pair.Key),
                                    Uri.EscapeDataString(pair.Value));
                }
                ub.Query = sb.ToString();

                request = (HttpWebRequest)WebRequest.Create(ub.Uri);
                request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback);
                request.Method      = "GET";
                request.Timeout     = Timeout;
                request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.BypassCache);

                request.BeginGetResponse(ResponseCallback, null);
            }
            else
            {
                // If heartbeats are disabled, the data is written to a text file (heartbeatdata.txt)
                const string tempFile = Paths.HeartbeatDataFileName + ".tmp";

                File.WriteAllLines(tempFile,
                                   new[] {
                    Server.Salt,
                    Server.IP.ToString(),
                    Server.Port.ToString(),
                    Server.CountPlayers(false).ToString(),
                    ConfigKey.MaxPlayers.GetString(),
                    ConfigKey.ServerName.GetString(),
                    ConfigKey.IsPublic.GetString()
                },
                                   Encoding.ASCII);

                Paths.MoveOrReplace(tempFile, Paths.HeartbeatDataFileName);
                RescheduleHeartbeat();
            }
        }
Beispiel #26
0
 static bool RaiseHeartbeatSendingEvent( HeartbeatData data, Uri uri, bool getServerUri ) {
     var h = Sending;
     if( h == null ) return true;
     var e = new HeartbeatSendingEventArgs( data, uri, getServerUri );
     h( null, e );
     return !e.Cancel;
 }
Beispiel #27
0
 public HeartbeatRequestState(HttpWebRequest request, HeartbeatData data, bool getServerUri)
 {
     Request      = request;
     Data         = data;
     GetServerUri = getServerUri;
 }
Beispiel #28
0
 public HeartbeatRequestState( HttpWebRequest request, HeartbeatData data, bool getServerUri ) {
     Request = request;
     Data = data;
     GetServerUri = getServerUri;
 }
Beispiel #29
0
 static bool RaiseHeartbeatSendingEvent( HeartbeatData data, Uri uri, bool getServerUri ) {
     var e = new HeartbeatSendingEventArgs( data, uri, getServerUri );
     SendingEvent.Raise( e );
     return !e.Cancel;
 }