# Core

```cpp
class Core {
    public:
        Core();
        ~Core(){};

        int checkArgs(int ac, char **av);
        void run();

    private:
        int _port;
        std::string _ip;
};
```

&#x20;Core class is use to verify command arguments, and set a port and an IP by default to connect with the server.

```cpp
void Core::run()
{
    Game game;
    game.MainLoop();
}
```

The run() function is used to start the game and call the game loop.

```cpp
int Core::checkArgs(int ac, char **av)
{
    if (ac < 2)
        return 0;
    if (ac > 5)
        throw MyError("Core", "Too many arguments.");
    if (std::string(av[1]).find("-help") != std::string::npos) {
        std::cout << "USAGE: ./client -p port -h machine\n\tport\tis the port number; 4242 by default\n\tmachine\tis the name of the machine; localhost by default" << std::endl;
        return -1;
    }

    for (int i = 0; i < ac; i++) {
        if (std::string(av[i]).find("-p") != std::string::npos) {
            if (av[i + 1] == NULL)
                throw MyError("Core", "You put the -p but no port after.");
            try {
                this->_port = std::stoi(av[i + 1]);
            } catch (std::exception &e) {
                throw MyError("Core", "Port is not a number.");
            }
        }
        if (std::string(av[i]).find("-h") != std::string::npos) {
            if (av[i + 1] == NULL)
                throw MyError("Core", "You put the -h but no IP adress after.");
            for (int j = 0; av[i + 1][j] != '\0'; j++) {
                if (av[i + 1][j] == '.')
                    continue;
                else if (av[i + 1][j] < '0' || av[i + 1][j] > '9')
                    throw MyError("Core", "IP adress is not a number.");
                else
                    this->_ip = av[i + 1];
            }
        }
    }
    return 0;
}
```

The checkArgs() function is used to check arguments of the binary.\
Start the client without argument take argument by default:

```cpp
Core::Core()
{
    this->_port = 4242;
    this->_ip = "127.0.0.1";
}
```

Use -h can set the IP to connect at the server.\
Use -p can set the port to connect at the server.\
Use -help to see the help prompt.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redboard.gitbook.io/r-type-1/client/core.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
