Coding server files for games like CSS or Gmod

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

Well i was wondering if C++ can code server files for multiplayer games such as Counter Strike Source, Or Garry's mod. I was hoping when i get experienced enough i would try this (as a side hobby) and would this be included in the Sam's learn C++ in 21days book? Also would it include how to code an engine

--Again sorry for the newbish questions, im kind of excited because i am learning the basis of C++ and i'm just thinking ahead :D

Also i was hoping to know What header files were or (.h) Because i use Microsoft Visual C++ 2008 express edition :D

Thanks for your time and responses
-Neon Ninja♦
"Java is C++ without the guns, knives, and clubs" <------- So true.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Coding server files for games like CSS or Gmod

Post by MarauderIIC »

Server files like... the part that decides what to send to a client? If so, yeah, C/++ is often used for both server-side and client-side software. Edit: If you're talking server-side mod .dll files, which is how Quake 2 does it (haven't played any counter-strike, tbh), C++ can be compiled to be a .dll file too.

As for header files:
Say that you have a class (defines an object, like a microwave)
If you have more than one .cpp file, and they all need to do various things, like one .cpp file has microwave.on and another .cpp file has microwave.explode, then they both need to know the definition of the object (what a 'microwave' is). So you put "what a microwave is" in a header file and do a #include "microwave.h" in each of your .cpp files that needs to know what a microwave is.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Re: Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

Well i mean like when you play Css you join a server, and i knew someone who used to do that and when i get good i wanted to try it, just wanted to know if it was possible. Thanks for replying :D

EDIT: im completely new to this but soon i will be good.... Hopefully with sam's help :D I didn't even know you can make more files like that and also with that microwave example all your doing is defining what the microwave is? and if i were to code server files would i have to define for every model/environment?
"Java is C++ without the guns, knives, and clubs" <------- So true.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Coding server files for games like CSS or Gmod

Post by MarauderIIC »

You can code a program that receives signals from counterstrike clients and sends signals back, yes. It'd be rather complex. Did I answer that question, yet?

Yeah, I'm just defining what a microwave is. No, you don't have to use objects in your programming. If you do use objects, it would be like so...

microwave.h

Code: Select all

class Microwave {
private:
    bool isOn;
    int itemsInMicrowave;
    bool isOpen;
    int timeLeft;
public:
    void Close();
    void InsertItems(int numItems); //open microwave and insert items
    void Finish();  //open microwave and remove all items
    void SetTime(int time);
    void PushStart();

    void UpdateStatus(); //call this once per second

    int GetTimeLeft();
};
microwave.cpp / defines all the functions we prototyped in microwave.h

Code: Select all

#include "microwave.h"
void Microwave::Close() {
    isOpen = false;
}

void Microwave::InsertItems(int numItems) {
    isOpen = true;
    itemsInMicrowave = numItems;
}

void Microwave::Finish() {
    isOn = false;
    itemsInMicrowave = 0;
    isOpen = true;
}

void Microwave::SetTime() {
    timeLeft = time;
}

void Microwave::PushStart() {
    if (isOpen == false)
        isOn = true;
}

void Microwave::UpdateStatus() {
   timeLeft--;
   if (timeLeft == 0)
       isOn = false;
}

int Microwave::GetTimeLeft() {
    return timeLeft;
}
main.cpp / uses a microwave / all that it and anything like this needs to know is what the parameters for the fns are, the 'linker step' will make them refer to the correct fns that are defined in microwave.cpp, so include microwave.h, not microwave.cpp

Code: Select all

#include "microwave.h"
int main() {
    Microwave microwave;
    microwave.InsertItems(5);
    microwave.Close();
    microwave.PushStart();
    while (microwave.GetTimeLeft() != 0) {
        Sleep(1000); //time in milliseconds, this is not a standard function
        microwave.UpdateStatus();
    }
    microwave.Finish();
    return 0; //returning from main means end of program
}
edit- If you did not use objects (that is, you would use the headers for function prototypes that many .cpp files would use, if you used them), this is called procedural programming... I think. If you do it this way you might as well use C instead of C++.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Re: Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

Oh i see what your saying! I'm coding to define the server info to send to he client? as well as the client receives the server's info? Btw, Thanks alot your being very helpful :D
"Java is C++ without the guns, knives, and clubs" <------- So true.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Coding server files for games like CSS or Gmod

Post by MarauderIIC »

Yeah your code would receive information sent over a network (your computer will receive this information and pass it to any program listening for it), and then your code would process this information and send an appropriate response. So instead of a Microwave you might define a Packet. :)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Re: Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

Ahh it soounds so hard, but im sure when i buy that book and start learning it will come around to being moderately hard :D Thanks again for your help :D
"Java is C++ without the guns, knives, and clubs" <------- So true.
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Re: Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

And sorry for the double post but After i make the (main.cpp) file, would i then make a header?
"Java is C++ without the guns, knives, and clubs" <------- So true.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Coding server files for games like CSS or Gmod

Post by dandymcgee »

I think a CS server is a great goal, but you should probably do something a lot more simple to get the basic idea of what's going on. Then slowly build you're way up to creating your own server.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Re: Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

hmm ok Thanks :D
"Java is C++ without the guns, knives, and clubs" <------- So true.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Coding server files for games like CSS or Gmod

Post by MarauderIIC »

NeonNinja♦ wrote:And sorry for the double post but After i make the (main.cpp) file, would i then make a header?
Doesn't matter what order you make the files in.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
NeonNinja♦
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 38
Joined: Sat Oct 25, 2008 4:55 pm
Location: Under your bed eating your couch :D

Re: Coding server files for games like CSS or Gmod

Post by NeonNinja♦ »

Oh :D Thanks for the helpful advice :mrgreen: Im on my way!
"Java is C++ without the guns, knives, and clubs" <------- So true.
Post Reply