1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#ifndef NET_EA_NETWORK_H |
25 |
|
|
#define NET_EA_NETWORK_H |
26 |
|
|
|
27 |
|
|
#include "net/serverinfo.h" |
28 |
|
|
|
29 |
|
|
PRAGMACLANG6GCC(GCC diagnostic push) |
30 |
|
|
PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast") |
31 |
|
|
#include "net/sdltcpnet.h" |
32 |
|
|
PRAGMACLANG6GCC(GCC diagnostic pop) |
33 |
|
|
|
34 |
|
|
struct PacketInfo; |
35 |
|
|
|
36 |
|
|
namespace Ea |
37 |
|
|
{ |
38 |
|
|
|
39 |
|
|
class Network notfinal |
40 |
|
|
{ |
41 |
|
|
public: |
42 |
|
|
Network(); |
43 |
|
|
|
44 |
|
|
A_DELETE_COPY(Network) |
45 |
|
|
|
46 |
|
|
virtual ~Network(); |
47 |
|
|
|
48 |
|
|
bool connect(const ServerInfo &server); |
49 |
|
|
|
50 |
|
|
void disconnect(); |
51 |
|
|
|
52 |
|
|
ServerInfo getServer() const A_WARN_UNUSED |
53 |
|
|
{ return mServer; } |
54 |
|
|
|
55 |
|
|
int getState() const A_WARN_UNUSED |
56 |
|
|
{ return mState; } |
57 |
|
|
|
58 |
|
|
const std::string &getError() const A_WARN_UNUSED |
59 |
|
|
{ return mError; } |
60 |
|
|
|
61 |
|
|
bool isConnected() const A_WARN_UNUSED |
62 |
|
|
{ return mState == CONNECTED; } |
63 |
|
|
|
64 |
|
|
int getInSize() const A_WARN_UNUSED |
65 |
|
|
{ return mInSize; } |
66 |
|
|
|
67 |
|
|
void skip(const int len); |
68 |
|
|
|
69 |
|
|
void flush(); |
70 |
|
|
|
71 |
|
|
void fixSendBuffer(); |
72 |
|
|
|
73 |
|
|
void pauseDispatch() |
74 |
|
|
{ mPauseDispatch = true; } |
75 |
|
|
|
76 |
|
|
// ERROR replaced by NET_ERROR because already defined in Windows |
77 |
|
|
enum |
78 |
|
|
{ |
79 |
|
|
IDLE = 0, |
80 |
|
|
CONNECTED, |
81 |
|
|
CONNECTING, |
82 |
|
|
DATA, |
83 |
|
|
NET_ERROR |
84 |
|
|
}; |
85 |
|
|
|
86 |
|
|
protected: |
87 |
|
|
friend int networkThread(void *data); |
88 |
|
|
|
89 |
|
|
void setError(const std::string &error); |
90 |
|
|
|
91 |
|
|
uint16_t readWord(const int pos) const A_WARN_UNUSED; |
92 |
|
|
|
93 |
|
|
bool realConnect(); |
94 |
|
|
|
95 |
|
|
void receive(); |
96 |
|
|
|
97 |
|
|
TcpNet::Socket mSocket; |
98 |
|
|
|
99 |
|
|
ServerInfo mServer; |
100 |
|
|
|
101 |
|
|
PacketInfo *mPackets; |
102 |
|
|
|
103 |
|
|
char *mInBuffer; |
104 |
|
|
char *mOutBuffer; |
105 |
|
|
unsigned int mInSize; |
106 |
|
|
unsigned int mOutSize; |
107 |
|
|
|
108 |
|
|
unsigned int mToSkip; |
109 |
|
|
|
110 |
|
|
int mState; |
111 |
|
|
std::string mError; |
112 |
|
|
|
113 |
|
|
SDL_Thread *mWorkerThread; |
114 |
|
|
SDL_mutex *mMutexIn; |
115 |
|
|
SDL_mutex *mMutexOut; |
116 |
|
|
int mSleep; |
117 |
|
|
bool mPauseDispatch; |
118 |
|
|
}; |
119 |
|
|
|
120 |
|
|
} // namespace Ea |
121 |
|
|
|
122 |
|
|
#endif // NET_EA_NETWORK_H |