/
tytyshka
/
Typing_Race_Game
Обзор
Документация
Войти
/
tytyshka
/
Typing_Race_Game
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
Client
GameClient/typing_client.cpp
86 строк
3 KB
tytyshka
Файлы клиента
16 дек 2025, 21:52
16 дек 2025, 21:52
7041c0b
Код
Авторство
О чём код?
//// ����������: �������� json.hpp � net_client.* � ������ //#include "net_client.h" //#include "json.hpp" //#include <iostream> //#include <thread> //#include <atomic> //#include <string> // //using json = nlohmann::json; // //int main() { // NetClient nc; // std::string host = "127.0.0.1"; // int port = 9000; // if (!nc.connect_to(host, port)) return 1; // // std::string username; // std::cout << "Enter username: "; // std::getline(std::cin, username); // // json auth = { {"type","AUTH"}, {"payload", { {"username", username} }} }; // nc.send_json(auth); // // std::atomic<bool> running{ true }; // // // reader thread: prints incoming messages // std::thread reader([&]() { // while (running) { // json m = nc.receive_next(); // if (m.is_null() || m.empty()) { running = false; break; } // std::cout << "[SRV] " << m.dump() << std::endl; // } // }); // // // simple CLI loop // while (running) { // std::cout << "> "; // std::string line; // if (!std::getline(std::cin, line)) break; // if (line == "quit") break; // if (line == "list") { // json q = { {"type","LIST_ROOMS"}, {"payload", json::object()} }; // nc.send_json(q); // } // else if (line.rfind("create ", 0) == 0) { // // create name max_players duration_ms // std::istringstream iss(line); // std::string cmd, name; // int maxp; uint64_t dur; // iss >> cmd >> name >> maxp >> dur; // if (name.empty()) name = "room"; // if (maxp <= 0) maxp = 2; // if (dur == 0) dur = 60000; // json q = { {"type","CREATE_ROOM"}, {"payload", { {"name", name}, {"max_players", maxp}, {"auto_start", false}, {"game_duration_ms", dur} }} }; // nc.send_json(q); // } // else if (line.rfind("join ", 0) == 0) { // std::istringstream iss(line); // std::string cmd, roomid; // iss >> cmd >> roomid; // json q = { {"type","JOIN_ROOM"}, {"payload", { {"room_id", roomid} }} }; // nc.send_json(q); // } // else if (line.rfind("start ", 0) == 0) { // std::istringstream iss(line); // std::string cmd, roomid; // iss >> cmd >> roomid; // json q = { {"type","START_GAME"}, {"payload", { {"room_id", roomid} }} }; // nc.send_json(q); // } // else if (line.size() == 1) { // // send key press // std::string s(1, line[0]); // json q = { {"type","KEY_PRESS"}, {"payload", { {"char", s} }} }; // nc.send_json(q); // } // else { // std::cout << "Commands: list, create <name> <maxp> <duration_ms>, join <room_id>, start <room_id>, <single-char to press>, quit\n"; // } // } // // running = false; // nc.disconnect(); // if (reader.joinable()) reader.join(); // return 0; //}