1 /*
2 * Copyright 2006 Serge van den Boom <svdb@stack.nl>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include "netplay.h"
20 #include "packetsenders.h"
21
22 #include "packet.h"
23 #include "packetq.h"
24 #include "netsend.h"
25
26
27 void
sendInit(NetConnection * conn)28 sendInit(NetConnection *conn) {
29 Packet_Init *packet;
30
31 packet = Packet_Init_create();
32 queuePacket(conn, (Packet *) packet);
33 }
34
35 void
sendPing(NetConnection * conn,uint32 id)36 sendPing(NetConnection *conn, uint32 id) {
37 Packet_Ping *packet;
38
39 packet = Packet_Ping_create(id);
40 queuePacket(conn, (Packet *) packet);
41 }
42
43 void
sendAck(NetConnection * conn,uint32 id)44 sendAck(NetConnection *conn, uint32 id) {
45 Packet_Ack *packet;
46
47 packet = Packet_Ack_create(id);
48 queuePacket(conn, (Packet *) packet);
49 }
50
51 void
sendReady(NetConnection * conn)52 sendReady(NetConnection *conn) {
53 Packet_Ready *packet;
54
55 packet = Packet_Ready_create();
56 queuePacket(conn, (Packet *) packet);
57 }
58
59 void
sendHandshake0(NetConnection * conn)60 sendHandshake0(NetConnection *conn) {
61 Packet_Handshake0 *packet;
62
63 packet = Packet_Handshake0_create();
64 queuePacket(conn, (Packet *) packet);
65 }
66
67 void
sendHandshake1(NetConnection * conn)68 sendHandshake1(NetConnection *conn) {
69 Packet_Handshake1 *packet;
70
71 packet = Packet_Handshake1_create();
72 queuePacket(conn, (Packet *) packet);
73 }
74
75 void
sendHandshakeCancel(NetConnection * conn)76 sendHandshakeCancel(NetConnection *conn) {
77 Packet_HandshakeCancel *packet;
78
79 packet = Packet_HandshakeCancel_create();
80 queuePacket(conn, (Packet *) packet);
81 }
82
83 void
sendHandshakeCancelAck(NetConnection * conn)84 sendHandshakeCancelAck(NetConnection *conn) {
85 Packet_HandshakeCancelAck *packet;
86
87 packet = Packet_HandshakeCancelAck_create();
88 queuePacket(conn, (Packet *) packet);
89 }
90
91 void
sendTeamName(NetConnection * conn,NetplaySide side,const char * name,size_t len)92 sendTeamName(NetConnection *conn, NetplaySide side, const char *name,
93 size_t len) {
94 Packet_TeamName *packet;
95
96 packet = Packet_TeamName_create(side, name, len);
97 queuePacket(conn, (Packet *) packet);
98 }
99
100 void
sendFleet(NetConnection * conn,NetplaySide side,const MeleeShip * ships,size_t shipCount)101 sendFleet(NetConnection *conn, NetplaySide side, const MeleeShip *ships,
102 size_t shipCount) {
103 size_t i;
104 Packet_Fleet *packet;
105
106 packet = Packet_Fleet_create(side, shipCount);
107
108 for (i = 0; i < shipCount; i++) {
109 packet->ships[i].index = (uint8) i;
110 packet->ships[i].ship = (uint8) ships[i];
111 }
112
113 queuePacket(conn, (Packet *) packet);
114 }
115
116 void
sendFleetShip(NetConnection * conn,NetplaySide side,FleetShipIndex shipIndex,MeleeShip ship)117 sendFleetShip(NetConnection *conn, NetplaySide side,
118 FleetShipIndex shipIndex, MeleeShip ship) {
119 Packet_Fleet *packet;
120
121 packet = Packet_Fleet_create(side, 1);
122
123 packet->ships[0].index = (uint8) shipIndex;
124 packet->ships[0].ship = (uint8) ship;
125
126 queuePacket(conn, (Packet *) packet);
127 }
128
129 void
sendSeedRandom(NetConnection * conn,uint32 seed)130 sendSeedRandom(NetConnection *conn, uint32 seed) {
131 Packet_SeedRandom *packet;
132
133 packet = Packet_SeedRandom_create(seed);
134 queuePacket(conn, (Packet *) packet);
135 }
136
137 void
sendInputDelay(NetConnection * conn,uint32 delay)138 sendInputDelay(NetConnection *conn, uint32 delay) {
139 Packet_InputDelay *packet;
140
141 packet = Packet_InputDelay_create(delay);
142 queuePacket(conn, (Packet *) packet);
143 }
144
145 void
sendSelectShip(NetConnection * conn,FleetShipIndex index)146 sendSelectShip(NetConnection *conn, FleetShipIndex index) {
147 Packet_SelectShip *packet;
148
149 packet = Packet_SelectShip_create((uint16) index);
150 queuePacket(conn, (Packet *) packet);
151 }
152
153 void
sendBattleInput(NetConnection * conn,BATTLE_INPUT_STATE input)154 sendBattleInput(NetConnection *conn, BATTLE_INPUT_STATE input) {
155 Packet_BattleInput *packet;
156
157 packet = Packet_BattleInput_create((uint8) input);
158 queuePacket(conn, (Packet *) packet);
159 }
160
161 void
sendFrameCount(NetConnection * conn,BattleFrameCounter frameCount)162 sendFrameCount(NetConnection *conn, BattleFrameCounter frameCount) {
163 Packet_FrameCount *packet;
164
165 packet = Packet_FrameCount_create((uint32) frameCount);
166 queuePacket(conn, (Packet *) packet);
167 }
168
169 #ifdef NETPLAY_CHECKSUM
170 void
sendChecksum(NetConnection * conn,BattleFrameCounter frameNr,Checksum checksum)171 sendChecksum(NetConnection *conn, BattleFrameCounter frameNr,
172 Checksum checksum) {
173 Packet_Checksum *packet;
174
175 packet = Packet_Checksum_create((uint32) frameNr, (uint32) checksum);
176 queuePacket(conn, (Packet *) packet);
177 }
178 #endif
179
180 void
sendAbort(NetConnection * conn,NetplayAbortReason reason)181 sendAbort(NetConnection *conn, NetplayAbortReason reason) {
182 Packet_Abort *packet;
183
184 packet = Packet_Abort_create((uint16) reason);
185 queuePacket(conn, (Packet *) packet);
186 }
187
188 void
sendReset(NetConnection * conn,NetplayResetReason reason)189 sendReset(NetConnection *conn, NetplayResetReason reason) {
190 Packet_Reset *packet;
191
192 packet = Packet_Reset_create((uint16) reason);
193 queuePacket(conn, (Packet *) packet);
194 }
195
196
197
198