Game Development Community

User Specified Server IP Address

by William Todd Scott · 07/03/2006 (6:26 pm) · 3 comments

Download Code File

Only two files will be modified by this resource:

example\starter.fps\client\ui\joinServerGui.gui
engine\game\net\serverQuery.cc

You can either replace the existing files with those included in the zip file I uploaded to this resource, or you can walk through the step-by-step process below. (The modifications are pretty minor, so doing them with winmerge should take no time at all.)

PLEASE BACKUP ALL FILES BEFORE MAKING ANY MODIFICATIONS!!!!!!

In the following walkthrough the bold lines are those that have been modified

Starting with joinServergui.gui make the following change

new GuiChunkedBitmapCtrl(JoinServerGui) {
   profile = "GuiContentProfile";
   horizSizing = "width";
   vertSizing = "height";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 8";
   visible = "1";
   bitmap = "./background.jpg";
   useVariable = "0";
   tile = "0";
   helpTag = "0";

   new GuiControl() {
      profile = "GuiWindowProfile";
      horizSizing = "center";
      vertSizing = "center";
      position = "60 80";
      [b]extent = "525 348";[/b]          <----Make the dialog box larger to add our controls

Then further down add this:

new GuiTextCtrl(JS_status) {
         profile = "GuiBigTextProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "243 14";
         extent = "266 40";
         minExtent = "266 40";
         visible = "1";
         maxLength = "255";
      };
[b]
      new GuiTextCtrl() {
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "13 321";
         Extent = "98 18";
         MinExtent = "8 2";
         Visible = "1";
         text = "Specific IP Address:";
         maxLength = "255";
      };
      new GuiTextEditCtrl(JS_IPAddress) {
         Profile = "GuiTextEditProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "119 321";
         Extent = "169 18";
         MinExtent = "8 2";
         Visible = "1";
         maxLength = "255";
         historySize = "0";
         password = "0";
         tabComplete = "0";
         sinkAllKeyEvents = "0";
         password = "0";
         passwordMask = "*";
      };
      new GuiButtonCtrl(JS_findServer) {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "top";
         position = "299 318";
         Extent = "90 23";
         MinExtent = "8 8";
         Visible = "1";
         Command = "Canvas.getContent().find();";
         text = "Find Server";
         groupNum = "-1";
         buttonType = "PushButton";
         active = "0";
         helpTag = "0";
      };
[/b]
   };
};


Then further down add this:

//----------------------------------------
function JoinServerGui::exit(%this)
{
   cancelServerQuery();
   Canvas.setContent(mainMenuGui);
}

[b]
function joinServerGui::find(%this)
{
   cancelServerQuery(); 
   clearServerList();
   %addr = JS_IPAddress.getText();
   querySingleServer(%addr, 0);
}
[/b]


Then in serverQuery.cc make the following changes:

ConsoleFunction( querySingleServer, void, 3, 3, "querySingleServer(address, flags);" )
{
   argc;

   NetAddress addr;
   char* addrText;

   addrText = dStrdup(argv[1]);
   U8 flags = dAtoi(argv[2]);


   Net::stringToAddress( addrText, &addr );
[b]   sActiveFilter.type = ServerFilter::Buddy; //added to ping a single server [/b]
   querySingleServer(&addr,flags);
}

A little further down make this change:

ConsoleFunction( getServerCount, int, 1, 1, "getServerCount();" )
{
   argv,argc;
   return gServerList.size();
}
[b]
ConsoleFunction(clearServerList, void, 1, 1, "clearServerList();")
{
   clearServerList();
}
[/b]

Ok, you will need to recompile the engine so that the changes to serverQuery.cc are incorporated into the executable.

That's it!

Now, when you click the 'Join' button on the main menu you the user can enter an IP address in the text field and click the 'find' button. If the server is found, the user can join the server in the usual way. (Note that the IP address should be in the following form 192.168.1.100:28000 - with the port specified).

If anyone has improvements or corrections please let me know and I will incorporate them into the resource.

I hope this is helpful.

Todd

#1
05/27/2006 (10:05 pm)
Just wanted to say thanks! This works great!
#2
05/31/2006 (7:23 pm)
Glad it helped!
#3
10/04/2006 (6:56 am)
This works really well :)

Thanks m8!