File indexing completed on 2024-04-14 14:32:00

0001 // Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com>
0002 //
0003 // This library is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU Lesser General Public
0005 // License version 2.1 as published by the Free Software Foundation.
0006 //
0007 // This library is distributed in the hope that it will be useful,
0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0010 // Lesser General Public License for more details.
0011 //
0012 // You should have received a copy of the GNU Lesser General Public License
0013 // along with this library; see the file COPYING.LIB.  If not, write to
0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015 // Boston, MA 02110-1301, USA.
0016 
0017 #ifndef LIBATLANTIK_NETWORK_H
0018 #define LIBATLANTIK_NETWORK_H
0019 
0020 #include "network_defs.h"
0021 
0022 #include <QMap>
0023 #include <QTextStream>
0024 #include <QDomNode>
0025 #include <QAbstractSocket>
0026 
0027 #include <libatlantikclient_export.h>
0028 
0029 class AtlanticCore;
0030 class Auction;
0031 class Card;
0032 class Estate;
0033 class EstateGroup;
0034 class Player;
0035 class Trade;
0036 class QTcpSocket;
0037 
0038 class  LIBATLANTIKCLIENT_EXPORT AtlantikNetwork: public QObject
0039 {
0040 Q_OBJECT
0041 
0042 public:
0043     AtlantikNetwork(AtlanticCore *atlanticCore);
0044     virtual ~AtlantikNetwork(void);
0045 
0046     void setName(const QString &name);
0047     void cmdChat(const QString &msg);
0048 
0049     QString host() const;
0050     int port() const;
0051 
0052     bool isConnected() const;
0053 
0054     void reset();
0055     void disconnect();
0056 
0057 private Q_SLOTS:
0058     void slotwriteData(const QString &msg);
0059     void slotLookupFinished();
0060     void slotConnectionSuccess();
0061     void slotConnectionFailed(QAbstractSocket::SocketError error);
0062     void slotDisconnected();
0063 
0064     void slotRead();
0065     void writeData(const QString &data);
0066 
0067 
0068     void rollDice();
0069     void endTurn();
0070     void newGame(const QString &gameType);
0071     void reconnect(const QString &cookie);
0072     void startGame();
0073     void buyEstate();
0074     void auctionEstate();
0075     void estateToggleMortgage(Estate *estate);
0076     void estateHouseBuy(Estate *estate);
0077     void estateHouseSell(Estate *estate);
0078     void estateSell(Estate *estate);
0079     void jailCard();
0080     void jailPay();
0081     void jailRoll();
0082     void newTrade(Player *player);
0083     void kickPlayer(Player *player);
0084     void tokenConfirmation(Estate *);
0085     void tradeUpdateEstate(Trade *trade, Estate *estate, Player *player);
0086     void tradeUpdateMoney(Trade *trade, unsigned int money, Player *pFrom, Player *pTo);
0087     void tradeUpdateCard(Trade *trade, Card *card, Player *pTo);
0088     void tradeReject(Trade *trade);
0089     void tradeAccept(Trade *trade);
0090     void auctionBid(Auction *auction, int amount);
0091     void changeOption(int, const QString &value);
0092 
0093 
0094 
0095 public Q_SLOTS:
0096     void serverConnect(const QString &host, int port);
0097 
0098     void joinGame(int gameId);
0099     void watchGame(int gameId);
0100     void leaveGame();
0101     void setImage(const QString &name);
0102 
0103 Q_SIGNALS:
0104     void connectionSuccess();
0105     void connectionFailed(QAbstractSocket::SocketError error);
0106     void disconnected();
0107 
0108     void msgInfo(const QString &);
0109     void msgError(const QString &);
0110     void msgChat(const QString &, const QString &);
0111     void msgStatus(const QString &data, EventType type);
0112     void networkEvent(const QString &data, EventType type);
0113     void displayDetails(const QString &text, bool clearText, bool clearButtons, Estate *estate = nullptr);
0114     void displayText(const QString &text, bool clearText, bool clearButtons);
0115     void addCommandButton(const QString &command, const QString &caption, bool enabled);
0116     void addCloseButton();
0117 
0118     void gameOption(const QString &title, const QString &type, const QString &value, const QString &edit, const QString &command);
0119     void endConfigUpdate();
0120 
0121     void gameConfig();
0122     void gameInit();
0123     void gameRun();
0124     void gameEnd();
0125     void receivedHandshake();
0126     void clientCookie(const QString &cookie);
0127     void newEstate(Estate *estate);
0128 
0129     void newEstateGroup(EstateGroup *estateGroup);
0130     void msgTradeUpdateAccepted(Trade *trade);
0131 
0132     void msgTradeUpdateRejected(Trade *trade, int playerId);
0133 
0134     void newAuction(Auction *auction);
0135     void auctionCompleted(Auction *auction);
0136 private:
0137         void processMsg(const QString &msg);
0138         void processNode(QDomNode);
0139     AtlanticCore *m_atlanticCore;
0140     QTcpSocket *m_monopdsocket;
0141     QTextStream m_monopdstream;
0142     int m_playerId;
0143     QString m_serverVersion;
0144     QMap<Player *, int> m_playerLocationMap;
0145     QString m_host;
0146     int m_port;
0147 };
0148 
0149 #endif