~ubuntu-branches/debian/sid/chessx/sid

« back to all changes in this revision

Viewing changes to src/database/ficsclient.cpp

  • Committer: Package Import Robot
  • Author(s): Niklas Fiekas
  • Date: 2014-10-06 18:26:02 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20141006182602-4kpiyz31knghkbrq
Tags: 1.2.2-1
* New upstream release.
  - Fix crash and data loss when trying to save a database other than the
    currently selected one.
  - Exclude autogenerated files from source tarball; fixes lintian warning
    source-contains-autogenerated-visual-c++-file.
  - Remove debian/patches/desktop-file.patch; applied upstream.
  - Remove debian/patches/desktop-mime-but-no-exec-code.patch; applied
    upstream.
* debian/chessx.6:
  - Adjust tagline in manpage.
* debian/rules:
  - Remove duplicate QT_SELECT=5.
* debian/control:
  - Update standards version to 3.9.6.0; no relevant changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
*   Copyright (C) 2014 by Jens Nissen jens-chessx@gmx.net                   *
 
3
****************************************************************************/
 
4
 
 
5
#include "ficsclient.h"
 
6
#include "settings.h"
 
7
 
 
8
FicsClient::FicsClient(QObject *parent):
 
9
    TelnetClient(parent)
 
10
{
 
11
}
 
12
 
 
13
void FicsClient::startSession()
 
14
{
 
15
    QString account = AppSettings->getValue("/FICS/userName").toString();
 
16
    QString passwd = AppSettings->getValue("/FICS/passWord").toString();
 
17
    connectHost("freechess.org", 5000, account, passwd);
 
18
}
 
19
 
 
20
void FicsClient::sendAccept()
 
21
{
 
22
    sendFicsCommand("accept");
 
23
}
 
24
 
 
25
void FicsClient::sendHistory()
 
26
{
 
27
    sendFicsCommand("history");
 
28
}
 
29
 
 
30
void FicsClient::sendPlayRequest(int gameId)
 
31
{
 
32
    QString cmd = QString("play %1").arg(gameId);
 
33
    sendFicsCommand(cmd);
 
34
}
 
35
 
 
36
void FicsClient::sendCommand(QString s)
 
37
{
 
38
    sendFicsCommand(s);
 
39
}
 
40
 
 
41
void FicsClient::sendObserve(int gameId)
 
42
{
 
43
    QString cmd = QString("observe %1").arg(gameId);
 
44
    sendFicsCommand(cmd);
 
45
}
 
46
 
 
47
void FicsClient::sendUnobserve(int gameId)
 
48
{
 
49
    QString cmd = QString("unobserve %1").arg(gameId);
 
50
    sendFicsCommand(cmd);
 
51
}
 
52
 
 
53
void FicsClient::sendFicsCommand(QString s)
 
54
{
 
55
    send(s);
 
56
}
 
57
 
 
58
void FicsClient::sendFicsCommandWithId(QString s, int id)
 
59
{
 
60
    s.prepend(QString("%1 ").arg(id));
 
61
    send(s);
 
62
}
 
63
 
 
64
void FicsClient::OnSessionStarted()
 
65
{
 
66
    sendFicsCommand("set seek 0");
 
67
    sendFicsCommand("set style 12");
 
68
    sendFicsCommand("set shout 0");
 
69
    sendFicsCommand("set cshout 0");
 
70
    sendFicsCommand("set gin 0");
 
71
    sendFicsCommand("set pin 0");
 
72
    sendFicsCommand("set mailmess 1");
 
73
    sendFicsCommand("- channel 1");
 
74
    sendFicsCommand("- channel 2");
 
75
    sendFicsCommand("- channel 50");
 
76
    sendFicsCommand("iset block 1");
 
77
    sendFicsCommandWithId("history",1);
 
78
    sendFicsCommandWithId("games",2);
 
79
}
 
80
 
 
81
void FicsClient::OnReceiveTelnetMessage(QString s)
 
82
{
 
83
    if (s.startsWith(StartReply))
 
84
    {
 
85
        switch (s[3].toLatin1())
 
86
        {
 
87
        case BLKCMD_HISTORY:
 
88
            s.remove(5);
 
89
            emit addNewHistoryEntry(s);
 
90
            break;
 
91
 
 
92
        case BLKCMD_GAMES:
 
93
            s.remove(5);
 
94
            emit addNewGameEntry(s);
 
95
            break;
 
96
        }
 
97
    }
 
98
}