1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#ifdef WIN32
#pragma warning (disable:4786)
#endif
#include "client_lobby.h"
#include "lobby_dialog.h"
#include <string>
#include <iostream>
/////////////////////////////////////////////////////////////////////////////
// ClientLobby construction:
ClientLobby::ClientLobby(const CL_NetSession &_session,const Options &_options)
: session(_session), options(_options), dialog(0)
{
}
ClientLobby::~ClientLobby()
{
}
/////////////////////////////////////////////////////////////////////////////
// ClientLobby Operations:
void ClientLobby::update()
{
if(session.peek(STC_NEW_LOGIN))
{
CL_NetMessage message = session.receive(STC_NEW_LOGIN);
CL_InputSource_Memory input(message.data);
bool result = input.read_bool8();
std::string text = input.read_string();
dialog->add_chatline(text);
dialog->set_login(result);
}
if (session.peek(STC_CHAT_LINE))
{
CL_NetMessage message = session.receive(STC_CHAT_LINE);
CL_InputSource_Memory input(message.data);
std::string text = input.read_string();
dialog->add_chatline(text);
}
if (session.peek(STC_CHAT_GLOBAL))
{
CL_NetMessage message = session.receive(STC_CHAT_GLOBAL);
CL_InputSource_Memory input(message.data);
std::string text = input.read_string();
dialog->add_chatline(text);
}
if (session.peek(STC_START_GAME))
{
CL_NetMessage message = session.receive(STC_START_GAME);
CL_InputSource_Memory input(message.data);
std::string text = input.read_string();
dialog->add_chatline(text);
dialog->set_result(LobbyDialog::LOBBY_GO);
}
if (session.peek(STC_JOIN_TEAM))
{
CL_NetMessage message = session.receive(STC_JOIN_TEAM);
CL_InputSource_Memory input(message.data);
int team = input.read_int32();
std::string name = input.read_string();
dialog->add_team_name(name, team);
}
}
void ClientLobby::login()
{
CL_OutputSource_Memory output;
output.write_string(options.get_player_name());
session.send(CTS_NEW_LOGIN, session.get_server(), output.get_data());
}
void ClientLobby::request_start_game(bool go)
{
// send to server that we want to start game
CL_OutputSource_Memory output;
output.write_bool8(go);
session.send(CTS_PLAYER_READY, session.get_server(), output.get_data());
}
void ClientLobby::join_team(int number)
{
// send to server that I want to join a specific team
CL_OutputSource_Memory output;
output.write_int32(number);
session.send(CTS_JOIN_TEAM,session.get_server(), output.get_data());
}
void ClientLobby::say_line(const std::string text)
{
CL_OutputSource_Memory output;
output.write_string(text);
session.send(CTS_CHAT_LINE, session.get_server(), output.get_data());
}
void ClientLobby::set_lobby_dialog(LobbyDialog *dlg)
{
dialog = dlg;
}
|