QTfrontend/netclient.h
author unc0rr
Fri, 16 Dec 2005 20:59:49 +0000
changeset 28 59f7db859b8a
child 29 9311259d5242
permissions -rw-r--r--
- clear demos list before adding items - start to implement net game
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     1
/*
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     4
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     6
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    13
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    21
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    32
 */
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    33
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    34
#ifndef NET_H
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    35
#define NET_H
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    36
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    37
#include <QObject>
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    38
#include <QTcpSocket>
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    39
#include <QRegExp>
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    40
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    41
class HWNet : public QObject
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    42
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    43
	Q_OBJECT
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    44
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    45
public:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    46
    HWNet();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    47
	void Connect(const QString & hostName, quint16 port);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    48
	void Disconnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    49
	void SendNet(const QString & buf);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    50
	void SendNet(const QByteArray & buf);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    51
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    52
signals:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    53
	void Connected();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    54
	void AddGame(const QString & chan);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    55
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    56
private:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    57
	enum NetState {
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    58
		nsDisconnected = 0,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    59
		nsConnecting   = 1,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    60
		nsConnected    = 3,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    61
		nsQuitting     = 5
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    62
	};
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    63
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    64
	QTcpSocket NetSocket;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    65
	NetState state;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    66
	QRegExp * IRCmsg_cmd_param;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    67
	QRegExp * IRCmsg_number_param;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    68
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    69
	void ParseLine(const QString & msg);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    70
	void msgcmd_paramHandler(const QString & msg);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    71
	void msgnumber_paramHandler(const QString & msg);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    72
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    73
private slots:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    74
	void ClientRead();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    75
	void OnConnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    76
	void OnDisconnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    77
	void Perform();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    78
	void displayError(QAbstractSocket::SocketError socketError);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    79
};
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    80
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    81
#endif