The online racing simulator
#1 - vane
Live status of server on php page from c# insim
what i am asking is can i for example type "!serverstatus {custom status}" then that is then displayed on a php page online. what i was thinking was the c# insim saves a .txt file to the host comp, the insim then uploads that to the website via ftp then the php page reads that status and puts it on the site. would this be possible?
#2 - Jakg
How often would this thing update? That sounds like a heck of a lot of work
What is the exact end goal? What stats do you want displayed? The only reason I'm asking is because I think you could probably acheive the same level of detail using a combination of hostsPORTNUMBER.txt file and LFSW pubstats
#4 - vane
what i mean is that you can put "insim being tested" instead of just having online and offline. i would make the insim only upload when it has been updated then whenever the php page loads, it loads from the .txt file
Best idea IMO, Set a db up on the remote machine. Have it save in there, Update it everytime a status changes. PHP could query a db easy.
#6 - gru
i wouldnt use txt files and ftp

i think Your insim should just run website with parameter
sth like:
http://my_page.com/index.php?server_status=testing

then php reads status and saves it in db

of course U must add some validation, so only Your app can change status
#7 - vane
do you think my way would work though? with my current skill level i would guess the .txt bit is the one that will be easiest for me to do :s
I'm sure I'll get kicked in the arse for this one, but I was browsing around MSDN for something else and did a quick check.

Fetching a URL in C# looks pretty simple - you just use the HttpWebRequest object, feed it a URL, and you're pretty much done.

Then all you'd need to do webserver side is setup a script to check and store that result (should be trivial if you're comfortable with PHP as all you'd need to do is read a $_GET variable). Nice and easy, whether you make it save to a text file at the server, or in a database, and much easier than dumping text files and uploading them using FTP!
#9 - gru
Haven't tested, but this should work to get a webpage contents (of course, you don't need the StreamReader if you just intend to use GET variables, so you can omit the entire try-catch block - it's in there for completeness). I haven't tested this, I've just lifted it from an old program I made.

Make sure you include:

using System.Net;
using System.IO;

String url = "http://blablabla.com";

HttpWebRequest rq;
HttpWebResponse re;

rq = (HttpWebRequest)WebRequest.Create(url);
rq.Timeout = 30000;

re = (HttpWebResponse)rq.GetResponse();

try {

StreamReader read = new StreamReader(
re.GetResponseStream(),
Encoding.GetEncoding("utf-8"));

String data = read.ReadToEnd();

} catch (WebException we) {
//
} catch (IOException ioe) {
//
}

read.Close();
re.Close();

#11 - vane
isn't that code for C#? and will it only be able to read, not write. The C# Insim (Application ) is the bit that would be uploading the info to the the site not vice versa
The suggestion was to use the WebResponse to pass the status as a query string to the web page.


string url = "http://blablabla.com/index.php?status=Hello World";

Then you can write a web page to deal with the query string as you see fit.


<?php echo $_GET['status']; ?>

#13 - vane
if the php page were to be the index and it goes to it as the start page would the status automatically show up? ill try it out thanks for all your help so far

edit: so i can put that under a "case "!serverstatus": " in the mso then make it send the StrMsg[1] to the website for the status?

edit2: i have got a really basic php page showing the status of it, is there any way of making it so people can just type what they want into the address bar to get the status they type?

http://reallife.10gbfreehost.c ... hp?status=Insim%20Testing
#14 - vane
im a bit confused as to how the web page actually stores the web status :s

EDIT: i have a feeling you do not fully understand me, what i wanted was a bit in my insim that i can type "!serverstatus STATUS" then "STATUS" will show up on the php web page when ever anyone goes onto the web page
The webpage in effect doesnt, The example DarkTimes posted. All that does is sends a request to a webpage with a value "status=online". When writing a PHP page you can(on page load or whatever) grab that value "status" and then either save it in a database, or basically what the hell you want with it. Cant be THAT hard to understand surly?
#16 - vane
I'm not too clear what you mean by database, could you enlighten me?
A computer database is a structured collection of records or data that is stored in a computer system. A database relies upon software to organize the storage of data. In other words, the software models the database structure in what are known as database models (or data models). The model in most common use today is the relational model. Other models such as the hierarchical model and the network model use a more explicit representation of relationships (see below for explanation of the various database models).
Database management systems are usually categorized according to the database model that they support. The data model tends to determine the query languages that are available to access the database. A great deal of the internal engineering of a DBMS, however, is independent of the data model, and is concerned with managing factors such as performance, concurrency, integrity, and recovery from hardware failures. In these areas there are large differences between products


Understand now?
#18 - gru
#19 - vane
i will probably also add a few more bits of info to it e.g maybe online usernames and amount of people on server
I may be talking out of turn here, I really don't have much experience with this. But it makes sense to me given everything that I have read so far...

The insim app should create a string that is the equivalent of a PHP serialized object, then it writes the string to a file on the web server, the web page then de-serializes the object and writes out the value on the page when rendered.

I just don't know C# well enough to give anymore details. But conceptually this sounds like what Vane is looking for.
#21 - vane
will it not need some details e.g ftp password to save a .txt file or any file to the site?
That mings, bdshan. Massively. For a start if anyone else got their hands on writing to that file, lots of interesting things could be made to happen.

If you really wanted to go down the uploading of files route, then just stick with a text file. However, uploading a file is supremely more complicated in C# than calling a URL.

There's nothing to say that a database has to be used at the web server side, it just needs to be recorded in some way.
#23 - vane
could you give it the ftp details then make it mod the .php file? this may be a crude way of doing it :s
i still do not see any way of saving a .txt file to a server with out any passwords or anything, if this was possible surely every website would be very simple to get into
I still think the best route is to just call the PHP page and pass in a query string, then you can write some simple PHP code to write it to a file or insert it into a database. That said, uploading a file with FTP in C# isn't actually that much harder than requesting a web page, but it seems like adding unnecessary complexity with little benefit to me.
#25 - vane
so what your saying is instead of using ftp to upload the .txt file, the php page gets the status then saves it to the .txt file and it can change it because it is on the server with the .txt file, would anyone be so kind as to possialy give me a few pointers or maybe give me a little bit of example code to try, i will also have to add a bit to stop people typing in the "query" url in the address bar and making the php page save their status.

FGED GREDG RDFGDR GSFDG