Jump to content

Service stopping


romatr

Recommended Posts

Hello,

 

I have a little trouble. I'm trying to make my own asp.net page to serv TCAdmin operations (start, stop, restart). I found several examples here on forum but have a trouble: on tcadmin services page I see that service (Half-Life counter-strike server) is running, but when I run my code

 

public bool StopTCService(string tcServiceID)
{
		
/*
Service service  = new Service();

s.ServiceID = tcServiceID;
if (s.Find() && (s.CurrentStatus == ServiceStatus.Running))
{
	return s.Stop();
}
*/
	
Service[] services = Service.GetServices();
foreach (Service s in services)
{
	if (s.ServiceID == tcServiceID &&  s.CurrentStatus == ServiceStatus.Running)
	{
		return s.Stop();
	}
}
return false;
}

 

and look for this service CurrentStatus - it is always `Unknown`.

 

What I do wrong?

Link to comment
Share on other sites

The examples here in the forums are meant to run directly on the server, in the form of a batch file. You would not be able to start,stop etc.. from an aspx page without interfacing with the API, since their is security in place that must be authenticated before any system level commands such as you are attempting can be done.

Link to comment
Share on other sites

The API documentation can be found in the SDK.chm located in your C:\Program Files\TCAdmin folder on your server.

 

It is not simply auth code, you have to interact with the API to perform these functions.

 

As with everyone looking at doing their own coding, I will say this up front. If you break it, we will not support it after you make any changes like what you are mentioning.

Link to comment
Share on other sites

OK,

 

I found .chm SDK help, but here is only class|methods|properties guide. I can not find any examples on how to make authentication. :(

 

P.S. My purpose is to make something like web service on ASP.NET to host at list three functions: start, stop and restart for game server. I have customer CP written on PHP and want to make possibility to operate this 3 functions from this panel. So I make ASP.NET web service hosted on the same computer with TCAdmin CP and plan to call this web service from other computer hosted my PHP web application. I do not plan to do any with TCAdmin self code or MySQL tcadmin database.

Link to comment
Share on other sites

Place this file in your TCAdmin Web folder. It stops the service you specify. I have tested it and it works.

 

You can test like this: http://your_ip/stop.aspx?serviceid=TCXXXXXXXXXXXX

 

You will need to add some kind of authentication so nobody else can stop your services.

 

<%
       Dim s As New TCAdminSDK.Objects.Service
       s.ServiceID = Request.QueryString("serviceid")
       If s.Find Then
           Response.Write("Old Status: " & s.CurrentStatus.ToString & "<br>")
           s.Stop()
           Response.Write("New Status: " & s.CurrentStatus.ToString)
       Else
           Response.Write("Service not found: " & s.ServiceID)
       End If
%>

Link to comment
Share on other sites

OK,

I found how to do this

 

<%@ Page language="c#" %>
<%
// ==============================================
TCAdminSDK.Web.Session session = new TCAdminSDK.Web.Session();
session.LogOn("admin", "password");
            // ==============================================

TCAdminSDK.Objects.Service s = new TCAdminSDK.Objects.Service();

   s.ServiceID = Request.QueryString["serviceid"];
if (s.Find())
{
	Response.Write("Old Status: " + s.CurrentStatus.ToString() + "<br>");
       s.Stop();
       Response.Write("New Status: " + s.CurrentStatus.ToString());
}
else
{
	Response.Write("Service not found: " + s.ServiceID);
}

%>

 

 

But question about different web application is still open ;-)

 

Thank you fo you help.

 

 

P.S. Is there any plan to make something like Quick Start Tutorial for TCAdmin SDK with real examples. Simple SDK objects guide is not enough for it effective use.

Link to comment
Share on other sites

I have not tried it but you should be able to create different web applications as long as your web.config is exactly the same as your tcadmin website (except for the log path which can be changed). You will have to add a reference TCAdminSDK.dll, TCAdminBase.dll and probably some of the other dlls in the Web/Bin folder.

 

We don't have a guide but you can look through all of the samples I have posted. Most of the objects work like this:

dim o as new tcadminobject

o.id = "TCXXXX"

if o.Find() then

o.Method()

o.Property = value

o.Save()

end if

 

I have also posted more complicated examples like creating a game server from script.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use