Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8271269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:47:46+00:00 2026-06-08T06:47:46+00:00

I have been working on the server code for my game. It works really

  • 0

I have been working on the server code for my game. It works really well, but 90% of the functions are in 1 class.

Usually I find it pretty easy to know how to divide things up. Either each object is a class or each dialog is a class and handles logic for its children.

In this case, the server receives a request, and then either tells the other players or processes and notifies the appropriate players.

Here is the header file:

    class ServerCore : public ServerHost, public NetEventListener,
        public ServerEventProvider
    {
        NetEventDecoder m_dec;
        NetEventEncoder m_enc;
        LoginManager m_login;

        ServerPlayerManager m_playerMan;
        ServerTableManager m_tableMan;

        void sendToTarget();
        void sendToAllActive();
        void sendToActiveNotTarget();
        void sendToTable(int tableNo);



    public:
        ServerCore();
        virtual void onConnect (Lacewing::Server::Client &client);
        virtual void onDisconnect (Lacewing::Server::Client &client);
        virtual void onError (Lacewing::Error &error);
        virtual void onReceive (Lacewing::Server::Client &client, char * data, int size);
        virtual void sendChatMessageC(const std::string& message,ChatAreaEnum area);
        virtual void requestTableC(int tableNo, int seatNo);
        virtual void playerRequestSitC(int tableNumber, int seatNumber);
        virtual void playerStoodUpC();
        virtual void hostGameC(const SpadesGameInfo& info);
        virtual void gameMessageC(SpadesCSMessageEnum message, const std::vector<int>& params);
        virtual void modifyListC(const std::string& player, GroupTypeEnum group, bool add);
        virtual void canceledHostingRequestC();
        virtual void sendInviteC(int tableNo, const std::string& player);

        virtual void loginResult(const std::string& name, ServerPlayer* player,
            const std::string& sessionID, bool success, bool newSession);
        virtual void readyToReceiveLobbyDataC();

        virtual void playerAbandonedGameC();
        virtual void watchTableC(int tableNo);

        virtual void gameCompleted(int tableId);

        virtual void playerWantsPlayAgainC();
        virtual ~ServerCore(void);
    };
}

I do not really know how I could break this down into smaller classes. The tasks they perform are handed to other objects, such as authentication, and data retrieval from database, but all events are currently processed in this 1 file.

The net event decoder calls the appropriate method after converting it from the string received over the wire.

Doing it this way works very well, but the game is going to get bigger and I want to stay clean and modular.

Is this design a good idea? If not, what type of patterns are usually used in game server development to keep things more object oriented?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:47:47+00:00Added an answer on June 8, 2026 at 6:47 am

    Looking at your class, the command pattern comes to mind. Indeed, the methods ending in C look very much like commands. If you have a command interface:

    class Command {
      virtual void execute() = 0;
    }
    

    and a separate subclass for each command, then the NetEventDecoder could decode the received string into a specific command.

    Also, anytime you find yourself passing the same data to multiple methods, that’s a hint that there’s a class hiding in there. For example, you could pull all the methods taking a tableNumber into a Table class. I would also get rid of the Manager classes and model the associations more directly.

    For example:

    // A game server contains players and tables
    class GameServer {
      map<string, Player *> players;
      map<int, Table *> tables;
    
      Player *findPlayer(const string &name);
      Table *findTable(int tableNumber);
      ...
    }
    
    // A player can perform various actions
    class Player {
      string name;
    
      bool requestSeat(Table *table);
      void standUp();
      ...
    }
    
    // A table maintains the status of seats
    class Table {
      int tableNumber;
    
      bool requestSeat(int seatNumber);
      ...
    }
    

    The GameServer class above simply models the game and does not deal with networking at all. The NetEventDecoder and ServerCore can then coordinate to provide networking functionality and invoke commands on the GameServer. An example command might look like:

    class PlayerStandUpCommand : public Command {
      GameServer *server;
      string playerName;
    
      void execute() {
        Player *player = server->findPlayer(playerName);
        player->standUp();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code which as been working against an older Active Directory server and
This code have been working until I updated last night. The code works perfectly
I have been working with SQL Server as a Developer a while. One thing
I have been working on designing a file server that could take the load
I am working on a server-side framework. Here and there I have been adding
I have an mp3 encoding server running on Ubuntu (natty). This has been working
I have been working on a project in C# (.net4). Project pretty much allows
I have been working on a project on and off, but I haven't touched
So I have been working on a 2 player Tic-Tac-Toe game in java that
I have been working on a prototype site using a mamp server and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.