~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/network_lan_promotion.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004 by the Widelands Development Team
 
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
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *
 
18
 */
 
19
 
 
20
#ifndef __NETWORK_LAN_PROMOTION_H__
 
21
#define __NETWORK_LAN_PROMOTION_H__
 
22
 
 
23
#include <list>
 
24
#include "network_system.h"
 
25
 
 
26
#define LAN_PROMOTION_PROTOCOL_VERSION  1
 
27
 
 
28
#define LAN_GAME_CLOSED         0
 
29
#define LAN_GAME_OPEN           1
 
30
 
 
31
struct LAN_Game_Info {
 
32
    char                magic[6];
 
33
    unsigned char       version;
 
34
    unsigned char       state;
 
35
    
 
36
    char                gameversion[32];
 
37
    char                hostname[32];
 
38
    char                map[32];
 
39
};
 
40
 
 
41
struct LAN_Open_Game {
 
42
    in_addr_t           address;
 
43
    in_port_t           port;
 
44
    LAN_Game_Info       info;
 
45
};
 
46
 
 
47
class LAN_Base {
 
48
    protected:
 
49
        LAN_Base ();
 
50
        ~LAN_Base ();
 
51
        
 
52
        void bind (unsigned short);
 
53
        
 
54
        bool avail ();
 
55
    
 
56
        ssize_t recv (void*, size_t, sockaddr_in*);
 
57
        
 
58
        void send (const void*, size_t, const sockaddr_in*);
 
59
        void broadcast (const void*, size_t, unsigned short);
 
60
    
 
61
    private:
 
62
        int                     sock;
 
63
        
 
64
        std::list<in_addr_t>    broadcast_addresses;
 
65
};
 
66
 
 
67
class LAN_Game_Promoter:LAN_Base {
 
68
    public:
 
69
        LAN_Game_Promoter ();
 
70
        ~LAN_Game_Promoter ();
 
71
        
 
72
        void run ();
 
73
        
 
74
        void set_map (const char*);
 
75
    
 
76
    private:
 
77
        LAN_Game_Info   gameinfo;
 
78
        bool            needupdate;
 
79
};
 
80
 
 
81
class LAN_Game_Finder:LAN_Base {
 
82
    public:
 
83
        enum {
 
84
            GameOpened,
 
85
            GameClosed,
 
86
            GameUpdated
 
87
        };
 
88
        
 
89
        LAN_Game_Finder ();
 
90
        ~LAN_Game_Finder ();
 
91
        
 
92
        void run ();
 
93
        
 
94
        void set_callback (void(*)(int, const LAN_Open_Game*, void*), void*);
 
95
    
 
96
    private:
 
97
        std::list<LAN_Open_Game*>       opengames;
 
98
        
 
99
        void (*callback) (int, const LAN_Open_Game*, void*);
 
100
        void*                           userdata;
 
101
};
 
102
 
 
103
#endif
 
104