blob: 4e02fb46cefe1676cc00ca81286ae0c684a35c4e (
plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#include "aoapplication.h"
#include "lobby.h"
#include "networkmanager.h"
#include "encryption_functions.h"
#include <QDebug>
void AOApplication::ms_packet_received(AOPacket *p_packet)
{
p_packet->net_decode();
QString header = p_packet->get_header();
QStringList f_contents = p_packet->get_contents();
if (header != "CHECK")
qDebug() << "R(ms):" << p_packet->to_string();
if (header == "ALL")
{
server_list.clear();
for (QString i_string : p_packet->get_contents())
{
server_type f_server;
QStringList sub_contents = i_string.split("&");
if (sub_contents.size() < 4)
{
qDebug() << "W: malformed packet";
continue;
}
f_server.name = sub_contents.at(0);
f_server.desc = sub_contents.at(1);
f_server.ip = sub_contents.at(2);
f_server.port = sub_contents.at(3).toInt();
server_list.append(f_server);
}
if (lobby_constructed)
{
w_lobby->list_servers();
}
}
else if (header == "CT")
{
QString message_line;
if (f_contents.size() == 1)
message_line = f_contents.at(0);
else if (f_contents.size() >= 2)
message_line = f_contents.at(0) + ": " + f_contents.at(1);
else
return;
if (lobby_constructed)
{
w_lobby->append_chatmessage(message_line);
}
if (courtroom_constructed)
{
//T0D0: uncomment this when it's implemented
//w_courtroom->append_ms_chat_message(message_line);
}
}
}
void AOApplication::server_packet_received(AOPacket *p_packet)
{
p_packet->net_decode();
QString header = p_packet->get_header();
QStringList f_contents = p_packet->get_contents();
QString f_packet = p_packet->to_string();
qDebug() << "R: " << f_packet;
if (header == "decryptor")
{
if (f_contents.size() == 0)
return;
//you may ask where 322 comes from. that would be a good question.
s_decryptor = fanta_decrypt(f_contents.at(0), 322).toUInt();
//T0D0 add an actual HDID here
AOPacket *hi_packet = new AOPacket("HI#ao2testinginprogressdontmindme#%");
send_server_packet(hi_packet);
delete hi_packet;
}
else if (header == "ID")
{
if (f_contents.size() < 1)
return;
}
else if (header == "CT")
{
if (f_contents.size() < 2)
{
qDebug() << "W: malformed packet!";
return;
}
//QString message_line = f_contents.at(0) + ": " + f_contents.at(1);
//T0D0, uncomment when implemented
//w_courtroom->append_ooc_chatmessage(message_line)
}
else if (header == "PN")
{
if (f_contents.size() < 2)
return;
w_lobby->set_player_count(f_contents.at(0).toInt(), f_contents.at(1).toInt());
}
}
void AOApplication::send_ms_packet(AOPacket *p_packet)
{
p_packet->net_encode();
QString f_packet = p_packet->to_string();
net_manager->ship_ms_packet(f_packet);
qDebug() << "S(ms):" << f_packet;
}
void AOApplication::send_server_packet(AOPacket *p_packet)
{
p_packet->net_encode();
QString f_packet = p_packet->to_string();
if (encryption_needed)
{
qDebug() << "S:(e)" << f_packet;
p_packet->encrypt_header(s_decryptor);
f_packet = p_packet->to_string();
}
else
{
qDebug() << "S:" << f_packet;
}
net_manager->ship_server_packet(f_packet);
}
|