// Responds to the Packets where we are establishing our connection with the server private void _handleConnectionSetupResponse(Packet packet) { // Check for accept and ACK if (packet.Type == PacketType.AcceptJoin) { // Make sure we haven't gotten it before if (_ourPaddle == null) { // See which paddle we are AcceptJoinPacket ajp = new AcceptJoinPacket(packet.GetBytes()); if (ajp.Side == PaddleSide.Left) { _ourPaddle = _left; } else if (ajp.Side == PaddleSide.Right) { _ourPaddle = _right; } else { throw new Exception("Error, invalid paddle side given by server."); // Should never hit this, but just incase } } // Send a response _sendAcceptJoinAck(); // Move the state _state = ClientState.WaitingForGameStart; } }
// Sends an AcceptJoinPacket to a player public void _sendAcceptJoin(PlayerInfo player) { // They need to know which paddle they are AcceptJoinPacket ajp = new AcceptJoinPacket(); ajp.Side = player.Paddle.Side; _sendTo(player, ajp); }