~armanelgtron/armagetronad/aaterminalclient.php

« back to all changes in this revision

Viewing changes to aaterminalclient.php

  • Committer: Armanelgtron
  • Date: 2021-04-05 23:09:29 UTC
  • Revision ID: armanelgtron@gmail.com-20210405230929-n3tddazefpnvofrj
the very beginnings of gGame stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
connection::$debug = false;
29
29
error_reporting(E_ERROR);
30
30
 
 
31
 
 
32
define("GS_CREATED",                    0); // newborn baby
 
33
define("GS_TRANSFER_SETTINGS",  7);
 
34
define("GS_CREATE_GRID",                10);
 
35
define("GS_CREATE_OBJECTS",             20);
 
36
define("GS_TRANSFER_OBJECTS",   30);
 
37
define("GS_CAMERA",                             35);
 
38
define("GS_SYNCING",                    40);
 
39
define("GS_SYNCING2",                   41);
 
40
define("GS_SYNCING3",                   42);
 
41
define("GS_PLAY",                               50);
 
42
define("GS_DELETE_OBJECTS",             60);
 
43
define("GS_DELETE_GRID",                70);
 
44
define("GS_STATE_MAX",                  80);
 
45
 
 
46
class gGame
 
47
{
 
48
        public $round;
 
49
        public $state;
 
50
        public $stateNext;
 
51
        
 
52
        function __construct()
 
53
        {
 
54
                $this->round = 0;
 
55
                $this->state = GS_CREATED;
 
56
                $this->stateNext = GS_TRANSFER_SETTINGS;
 
57
        }
 
58
        
 
59
        function SetState($act,$next)
 
60
        {
 
61
                $this->state = $act;
 
62
        }
 
63
        
 
64
        function StateUpdate()
 
65
        {
 
66
                if($this->state == GS_CREATED)
 
67
                        $this->stateNext = GS_PLAY;
 
68
                while($this->state != $this->stateNext)
 
69
                {
 
70
                        switch($this->state)
 
71
                        {
 
72
                                case GS_DELETE_GRID:
 
73
                                        print("Deleting grid...\n");
 
74
                                        exit_game_objects(grid);
 
75
                                        $this->SetState(GS_CREATE_GRID,GS_CREATE_OBJECTS);
 
76
                                        break;
 
77
                                
 
78
                                case GS_CREATED:
 
79
                                case GS_CREATE_GRID:
 
80
                                        print("Creating grid...\n");
 
81
                                        $this->SetState(GS_CREATE_OBJECTS,GS_TRANSFER_OBJECTS);
 
82
                                        break;
 
83
                                
 
84
                                case GS_TRANSFER_OBJECTS:
 
85
                                        $this->SetState(GS_CAMERA,GS_SYNCING);
 
86
                                        break;
 
87
                                
 
88
                                case GS_CAMERA:
 
89
                                        $this->SetState(GS_SYNCING,GS_PLAY);
 
90
                                        break;
 
91
                                
 
92
                                case GS_SYNCING:
 
93
                                        //print("New Round\n");
 
94
                                        $this->SetState(GS_PLAY,GS_PLAY);
 
95
                                        // sync game timer
 
96
                                        break;
 
97
                                
 
98
                                case GS_PLAY:
 
99
                                        $this->SetState(GS_DELETE_OBJECTS,GS_DELETE_GRID);
 
100
                                        break;
 
101
                                
 
102
                                case GS_CREATE_OBJECTS:
 
103
                                        //print("Creating objects...\n");
 
104
                                        $this->SetState(GS_TRANSFER_OBJECTS,GS_CAMERA);
 
105
                                        break;
 
106
                                
 
107
                                case GS_PLAY:
 
108
                                        $this->SetState(GS_DELETE_OBJECTS,GS_DELETE_GRID);
 
109
                                        break;
 
110
                                
 
111
                                case GS_DELETE_OBJECTS:
 
112
                                        print("Deleting objects...\n");
 
113
                                        $this->SetState(GS_DELETE_GRID,GS_CREATE_GRID);
 
114
                                        break;
 
115
                        }
 
116
                }
 
117
                $this->WriteSync();
 
118
        }
 
119
        
 
120
        public $connection;
 
121
        function WriteSync($connection=null)
 
122
        {
 
123
                if($connection == null) $connection = $this->connection;
 
124
                
 
125
                $msg = nMessage::makeMsg(311);
 
126
                $msg->writeshort($this->state);
 
127
                $connection->send($msg);
 
128
        }
 
129
}
 
130
 
31
131
class Client extends connection
32
132
{
33
133
    function send($msg)
131
231
                                        case 220: $cont = $this->handleNewTeam          ($msg); break;
132
232
                                        case 24:  $cont = $this->handleNetSync          ($msg); break;
133
233
                                        case 40:  $cont = $this->handleAuthRequest      ($msg); break;
 
234
                                        case 310: $cont = $this->handleGame             ($msg); break;
134
235
                                        default: if(connection::$debug) print_r($msg);
135
236
                                }
136
237
                        }
232
333
        {
233
334
                #print_r($thing);
234
335
        }
 
336
        function handleGame($msg)
 
337
        {
 
338
                $msgstate = $msg->readshort();
 
339
                
 
340
                if(!isset($this->game))
 
341
                {
 
342
                        $this->game = new gGame();
 
343
                        $this->game->connection = $this;
 
344
                        $this->game->WriteSync();
 
345
                        
 
346
                        // Eh, this is good enough for now...
 
347
                        while($this->game->state != GS_PLAY)
 
348
                        {
 
349
                                $this->game->StateUpdate();
 
350
                        }
 
351
                }
 
352
                return true;
 
353
        }
235
354
        function onFreeID($ids)
236
355
        {
237
356
                foreach($ids as $id)