~ubuntu-branches/debian/sid/monopd/sid

« back to all changes in this revision

Viewing changes to .pc/01_gcc43_includes.patch/src/main.cpp

  • Committer: Package Import Robot
  • Author(s): Markus Koschany
  • Date: 2014-02-28 15:39:47 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140228153947-1a5z05x3alj61wx1
Tags: 0.9.5-1
* Imported Upstream version 0.9.5.
  - Add support for IPv6 and systemd.
* Update watch file and point to the new upstream location
  at tuxfamily.org.
* Drop all patches. Merged upstream.
* debian/control:
  - Drop libcapsinetwork-dev from Build-Depends.
    Essential features of libcapsinetwork were merged into monopd and
    IPv6 support was added.
  - Add pkg-config to Build-Depends.
  - Add libsystemd-daemon-dev [linux-any] to Build-Depends.
  - Update homepage field and point to gtkatlantic.gradator.net.
* Add monopd.service and monopd.socket file and support systemd.
* Update monopd.6 man page.
* Use dh-systemd helper.
* Update debian/copyright. Add new BSD license.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) 2001-2004 Rob Kaper <cap@capsi.com>,
2
 
//               2001 Erik Bourget <ebourg@cs.mcgill.ca>
3
 
//
4
 
// This program is free software; you can redistribute it and/or
5
 
// modify it under the terms of the GNU General Public License
6
 
// version 2 as published by the Free Software Foundation.
7
 
//
8
 
// This program is distributed in the hope that it will be useful,
9
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
// General Public License for more details.
12
 
//
13
 
// You should have received a copy of the GNU General Public License
14
 
// along with this program; see the file COPYING.  If not, write to
15
 
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16
 
// Boston, MA 02111-1307, USA.
17
 
 
18
 
#include <signal.h>
19
 
#include <syslog.h>
20
 
#include <unistd.h>
21
 
 
22
 
#include <iostream>
23
 
#include <string>
24
 
 
25
 
#include <libcapsinetwork/listener.h>
26
 
#include <libcapsinetwork/socket.h>
27
 
 
28
 
#include "const.h"
29
 
#include "main.h"
30
 
#include "server.h"
31
 
 
32
 
MonopdListener::MonopdListener( MonopdServer *server )
33
 
 :      Listener(),
34
 
        m_server( server )
35
 
{
36
 
        if ( addListenPort( server->port() ) == -1 )
37
 
        {
38
 
                syslog( LOG_ERR, "could not bind port %d, exiting", server->port() );
39
 
                exit(1);
40
 
        }
41
 
        else
42
 
                syslog( LOG_NOTICE, "listener: port=[%d]", server->port() );
43
 
}
44
 
 
45
 
void MonopdListener::socketHandler( Socket *socket, const std::string &data )
46
 
{
47
 
        switch( socket->status() )
48
 
        {
49
 
                case Socket::New:
50
 
                        syslog( LOG_INFO, "connection: fd=[%d], ip=[%s]", socket->fd(), socket->ipAddr().c_str() );
51
 
                        socket->ioWrite( std::string("<monopd><server version=\"") + MONOPD_VERSION_STRING + "\"/></monopd>\n" );
52
 
                        m_server->initSocketTimeoutEvent( socket->fd() );
53
 
                        break;
54
 
 
55
 
                case Socket::Close:
56
 
                case Socket::Closed:
57
 
                        syslog( LOG_INFO, "disconnect: fd=[%d], ip=[%s]", socket->fd(), socket->ipAddr().c_str() );
58
 
                        m_server->closedSocket( socket );
59
 
                        break;
60
 
                        
61
 
                case Socket::Ok:
62
 
                        m_server->processInput( socket, data );
63
 
                        break;
64
 
        }
65
 
}
66
 
 
67
 
int main(int argc, char **argv)
68
 
{
69
 
        srand( (unsigned) time(0) );
70
 
        signal( SIGPIPE, SIG_IGN );
71
 
 
72
 
        openlog( "monopd", LOG_PID, LOG_DAEMON );
73
 
        syslog( LOG_NOTICE, "monopd %s started", MONOPD_VERSION_STRING );
74
 
 
75
 
        MonopdServer *server = new MonopdServer();
76
 
        if ( argc > 1 )
77
 
                server->setPort( atoi(argv[1]) );
78
 
 
79
 
        MonopdListener *listener = new MonopdListener( server );
80
 
 
81
 
        // close stdin, stdout, stderr
82
 
        // close(0); close(1); close(2);
83
 
 
84
 
        server->initMonopigatorEvent();
85
 
 
86
 
        for(;;)
87
 
        {
88
 
                // Check for network events
89
 
                listener->checkActivity();
90
 
 
91
 
                // Check for scheduled events in the timer
92
 
                int fd = server->processEvents();
93
 
                if(fd != -1)
94
 
                {
95
 
                        Socket *delSocket = listener->findSocket(fd);
96
 
                        if (delSocket && !server->findPlayer(delSocket))
97
 
                                delSocket->setStatus(Socket::Close);
98
 
                }
99
 
        }
100
 
 
101
 
        // Clean up memory
102
 
        delete server;
103
 
        delete listener;
104
 
 
105
 
        return 0;
106
 
}