File indexing completed on 2024-05-12 04:04:15
0001 /* 0002 This file is part of Knights, a chess board for KDE SC 4. 0003 SPDX-FileCopyrightText: 2009-2010 Miha Čančula <miha.cancula@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #ifndef KNIGHTS_FICSPROTOCOL_H 0009 #define KNIGHTS_FICSPROTOCOL_H 0010 0011 #include "proto/textprotocol.h" 0012 #include <gamemanager.h> 0013 0014 #include <QRegExp> 0015 0016 namespace Knights { 0017 class FicsDialog; 0018 class ChatWidget; 0019 0020 typedef QPair<QString, int> FicsPlayer; 0021 0022 struct FicsGameOffer { 0023 FicsPlayer player; 0024 int baseTime; 0025 int timeIncrement; 0026 bool rated; 0027 QString variant; 0028 Color color; 0029 bool manual; 0030 bool formula; 0031 int gameId; 0032 QPair< int, int > ratingRange; 0033 bool automatic; 0034 }; 0035 0036 struct FicsChallenge { 0037 FicsPlayer player; 0038 int gameId; 0039 }; 0040 0041 enum Stage { 0042 ConnectStage, 0043 SeekStage, 0044 PlayStage 0045 }; 0046 0047 class FicsProtocol : public TextProtocol { 0048 Q_OBJECT 0049 public: 0050 explicit FicsProtocol(QObject* parent = nullptr); 0051 ~FicsProtocol() override; 0052 0053 Features supportedFeatures() override; 0054 0055 void startGame() override; 0056 void move ( const Move& m ) override; 0057 QList<ToolWidgetData> toolWidgets() override; 0058 0059 void makeOffer(const Offer& offer) override; 0060 void acceptOffer(const Offer& offer) override; 0061 void declineOffer(const Offer& offer) override; 0062 0063 private: 0064 const QString movePattern; 0065 const QRegExp seekExp; 0066 const QRegExp challengeExp; 0067 const QRegExp moveStringExp; 0068 const QRegExp moveRegExp; 0069 const QRegExp gameStartedExp; 0070 const QRegExp offerExp; 0071 0072 Stage m_stage; 0073 QString password; 0074 bool sendPassword; 0075 FicsDialog* m_widget; 0076 bool m_seeking; 0077 ChatWidget* m_chat; 0078 QMap<int, Offer> m_offers; 0079 QString otherPlayerName; 0080 0081 Color parseColor( QString str ); 0082 bool parseLine(const QString& line) override; 0083 bool parseStub(const QString& line) override; 0084 0085 public Q_SLOTS: 0086 void init () override; 0087 virtual void resign(); 0088 0089 void socketError(); 0090 void dialogRejected(); 0091 void acceptSeek ( int id ); 0092 void acceptChallenge ( int id ); 0093 void declineChallenge ( int id ); 0094 void login(const QString& username, const QString& password); 0095 void sendChat ( QString text ); 0096 0097 void openGameDialog(); 0098 void setSeeking ( bool seek ); 0099 void setupOptions(); 0100 0101 Q_SIGNALS: 0102 void sessionStarted(); 0103 void clearSeeks(); 0104 void gameOfferRemoved ( int id ); 0105 void gameOfferReceived ( const FicsGameOffer& offer ); 0106 void challengeReceived ( const FicsChallenge& challenge ); 0107 void challengeRemoved ( int id ); 0108 }; 0109 } 0110 0111 #endif // KNIGHTS_FICSPROTOCOL_H