~ubuntu-branches/ubuntu/saucy/ricochet/saucy

« back to all changes in this revision

Viewing changes to ricochet-0.1/debian/ricochet/usr/share/ricochet/server.5c

  • Committer: Package Import Robot
  • Author(s): Keith Packard
  • Date: 2012-06-11 13:37:57 UTC
  • Revision ID: package-import@ubuntu.com-20120611133757-zn0ukd22vz56ymto
Tags: 0.3
* Improve appearance of board
* Fix user list when removing/adding same user

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id$
3
 
 *
4
 
 * Copyright © 2003 Keith Packard
5
 
 *
6
 
 * Permission to use, copy, modify, distribute, and sell this software and its
7
 
 * documentation for any purpose is hereby granted without fee, provided that
8
 
 * the above copyright notice appear in all copies and that both that
9
 
 * copyright notice and this permission notice appear in supporting
10
 
 * documentation, and that the name of Keith Packard not be used in
11
 
 * advertising or publicity pertaining to distribution of the software without
12
 
 * specific, written prior permission.  Keith Packard makes no
13
 
 * representations about the suitability of this software for any purpose.  It
14
 
 * is provided "as is" without express or implied warranty.
15
 
 *
16
 
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
 
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
 
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
 
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
 
 * PERFORMANCE OF THIS SOFTWARE.
23
 
 */
24
 
 
25
 
autoload RR;
26
 
autoload Mutex;
27
 
 
28
 
namespace Server {
29
 
 
30
 
    import RR;
31
 
 
32
 
    public typedef Client;
33
 
    public typedef Game;
34
 
 
35
 
    mutex   server_mutex = Mutex::new ();
36
 
 
37
 
    string      server_id = Sockets::gethostname();
38
 
 
39
 
    public void set_server_id (string id) { server_id = id; }
40
 
 
41
 
    const int server_version = 1;
42
 
 
43
 
    public bool lock () {
44
 
        Mutex::acquire (server_mutex);
45
 
#       File::fprintf (stderr, "lock %v\n", Thread::current());
46
 
        return true;
47
 
    }
48
 
 
49
 
    public bool unlock () {
50
 
#       File::fprintf (stderr, "unlock %v\n", Thread::current());
51
 
        Mutex::release (server_mutex);
52
 
        return true;
53
 
    }
54
 
 
55
 
    public typedef struct {
56
 
        int     x, y;
57
 
        Object  object;
58
 
    } ObjectLoc;
59
 
 
60
 
    public typedef union {
61
 
        void    none;
62
 
        string  username;
63
 
    } User;
64
 
 
65
 
    public typedef union {
66
 
        void    none;
67
 
        &Game   game;
68
 
    } GameRef;
69
 
 
70
 
    public typedef struct {
71
 
        int     number;
72
 
        int     sequence;
73
 
    } BidValue;
74
 
    
75
 
    public typedef union {
76
 
        void        none;
77
 
        BidValue    bid;
78
 
    } Bid;
79
 
    
80
 
    public typedef struct {
81
 
        file        f;
82
 
        User        user;
83
 
        GameRef     game;
84
 
        int         score;
85
 
        int         games;
86
 
        int         version;
87
 
        Bid         bid;
88
 
        bool        playing;
89
 
        bool        abandon;
90
 
        bool        nobid;
91
 
    } Client;
92
 
 
93
 
    public typedef union {
94
 
        void    none;
95
 
        int     seconds;
96
 
    } Time;
97
 
 
98
 
    public typedef union {
99
 
        void    none;
100
 
        &Client client;
101
 
    } ClientRef;
102
 
    
103
 
    public typedef union {
104
 
        void    none;
105
 
        Board   board;
106
 
    } BoardOrNone;
107
 
 
108
 
    public typedef struct {
109
 
        string          name;
110
 
        GameState       state;
111
 
        (&Client)[*]    clients;
112
 
        Target[*]       targets;
113
 
        Target          target;
114
 
        Board           board;
115
 
        int             expire_interval;
116
 
        int             expire_time;
117
 
        int             bid_sequence;
118
 
        ClientRef       active;
119
 
        ObjectLoc[*]    history;
120
 
        int             timer_serial;
121
 
        ObjectLoc[*]    done_robots;
122
 
    } Game;
123
 
 
124
 
    public exception notreached ();
125
 
}