Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Dallas, Tx
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Hey guys i need some help for my game server

    Hey everyone i have a minecraft server and i have a website to go along with it, and what i am trying to do is have a server status light to change automatically when i run my game server and when i close it. i have two pictures to be displayed when the server is up and when it is down.

    here is a clip of my code that is directly in the body tag and at the end is the divs i want it to fill in so it can read the external file and to change the img icon automatically:

    Code:
    <script type="text/javascript"> //Status Light
    		var ifOnline;
    	    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    		  ifOnline=new XMLHttpRequest();
    		} else {// code for IE6, IE5
    		  ifOnline=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		ifOnline.open("GET","/MINECRAFT_SERVER/server_status.txt",false);
    		ifOnline.send();
    		
    		var isitOnline=ifOnline.responseText;
    		
    		if (isitOnline == "0") {
    		  document.getElementById("testtest").innerHTML = "offline";
    		  document.getElementById("Status_Light").src = "_img/red_light.png";
    		} else if (isitOnline == "1") {
    		    document.getElementById("testtest").innerHTML = "online";
    		    document.getElementById("Status_Light").src = "_img/green_light.png";
    		}
    	  </script>
    	    <div class="server_idtext">Server IP: cozzycraft.zapto.org</div>
    		<div class="server_status_light"><img id="Status_Light" src=""/></div>
    		<div id="testtest"></div>
    if anyone can help it would be much appriciated

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    You never said what your problem was.
    These lines are wrong
    Code:
    ifOnline.open("GET","/MINECRAFT_SERVER/server_status.txt",false);
    ifOnline.send();
    S/B
    Code:
    ifOnline.open("GET","./MINECRAFT_SERVER/server_status.txt",true);
    ifOnline.send('');
    And Put the javascript after the page has loaded so the js can modify it.

    This works:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>New document</title>
    </head>
    <body>
    <div class="server_idtext">Server IP: cozzycraft.zapto.org</div>
    <div class="server_status_light"><img id="Status_Light" src=""/></div>
    <div id="testtest"></div>
    
    <script type="text/javascript"> //Status Light
    var ifOnline;
    if (window.XMLHttpRequest)// code for IE7+, Firefox, Chrome, Opera, Safari
    {
    	ifOnline=new XMLHttpRequest();
    } else {// code for IE6, IE5
    	ifOnline=new ActiveXObject("Microsoft.XMLHTTP");
    }
    ifOnline.onreadystatechange = function()
    {
        if (ifOnline.readyState == 4) {
    	    if (ifOnline.status == 200) {
    
    		isitOnline = ifOnline.responseText;
    		if (isitOnline == "0") {
    		document.getElementById("testtest").innerHTML = "offline";
    		document.getElementById("Status_Light").src = "_img/red_light.png";
    		} else if (isitOnline == "1") {
    			    document.getElementById("testtest").innerHTML = "online";
    			    document.getElementById("Status_Light").src = "_img/green_light.png";
    			}
    	    } else {
    	        	alert('There was a problem with the request. '+ ifOnline.status);
    	    	}
    	}
    }
    ifOnline.open("GET","./MINECRAFT_SERVER/server_status.txt",true);
    ifOnline.send('');
    </script>
    </body>
    </html>

  • Users who have thanked sunfighter for this post:

    Cozzimoto (01-16-2012)

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Dallas, Tx
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you for the reply.

    i put your script in my webpage, but the js isnt modifying the img.src still.

    what my problem is i have a .bat file to write a 1 or a 0 in a seperate txt file (server_status.txt) so the server would read online or offline. and what im trying to do with that file is use a simple script to read that file automatically and if ajax reads it as a 1 then it changes the img to a green light icon i have, and if it reads a 0 then it changes it to a red light icon.

    i have learned to now put js at the end of the webpage for it to load everything before modifying it, its just im still having a lil trouble. =/

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    That script works on my server. It looks like you are not connecting to the txt file.
    Change the ./MINECRAFT_SERVER/server_status.txt to /MINECRAFT_SERVER/server_status.txt and then to nothing ie; MINECRAFT_SERVER/server_status.txt

    and see if one of those works.

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Dallas, Tx
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    no same problem. does it help if i tell you im hosting on my own computer with IIS 7 and the host i am using is No-ip??

    like is there maybe a setting in my server that is stopping me from what i wanna do.

    this is the website address: http://cozzycraft.zapto.org/
    and your test file you wrote for me is here: http://cozzycraft.zapto.org/test.html

    and it loads perfectly on my computer and ive tested it on other computers out of my home network. i just dont understand the problem now if it isnt the script.
    Last edited by Cozzimoto; 01-16-2012 at 08:08 PM.

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    I think your right. How could a large great grand really really trustworthy company like microsoft miss this?

    I found this link http://ssysadmin.com/developers/enab...s7-server.html and this
    Windows 2008 \ IIS 7 doesn't have the axd handler mapping set up by default for using Ajax so you need to put the following code into your web.config file if you want to use Ajax and are on one of our Windows 2008 hosting plans.

    <system.webServer>
    <handlers>
    <add name="Ajax" path="*.axd" verb="*" modules="IsapiModule"
    scriptProcessor="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
    resourceType="Unspecified"
    preCondition="classicMode,runtimeVersionv2.0,bitness32" />
    </handlers>
    </system.webServer>
    on the internet.

  • Users who have thanked sunfighter for this post:

    Cozzimoto (01-16-2012)

  • #7
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Dallas, Tx
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    im running windows 7 64 bit and i clipped it in on my index and i get a error 500 now. IIS is becoming more of a headache now =/

    another thing i dont get why i would need to enable ajax is i already have two other elements running on the homepage that use ajax. i have a news feed in an xml file and i also have an alerts update in a seperate file as well that i use ajax to fetch
    Last edited by Cozzimoto; 01-16-2012 at 08:42 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •