/*
 * Kangaroo Punch MultiPlayer Game Server Mark II
 * Copyright (C) 2020-2021  Scott Duensing
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */


#ifndef CLIENT_H
#define CLIENT_H


#include "os.h"
#include "packet.h"


#define PING_STATS_SIZE  100


typedef struct ClientRawPacketS {
	char     *data;
	uint32_t  length;
} ClientRawPacketT;

typedef struct ClientThreadS {
	// System Stuff.
	uint64_t            threadIndex;
	pthread_t           threadHandle;
	pthread_attr_t      threadAttributes;
	uint8_t             running;
	PacketThreadDataT  *packetThreadData;
	ClientRawPacketT  **packetQueue;
	pthread_mutex_t     packetQueueMutex;
	struct timespec     pingStart;
	double              pingStats[PING_STATS_SIZE];
	uint8_t             pingHead;
	double              pingAverage;
	double              pingHigh;
	double              pingLow;
	void               *peer;
	// User State Stuff.
	uint8_t             authenticated;  // Is the user logged in?
	FILE               *handle;         // Handle of file currently being transferred to client.
	uint32_t            fileSize;       // Length of current file being transferred.
} ClientThreadT;


void  clientQueuePacket(ClientThreadT *client, uint8_t *data, uint32_t length);
void  clientShutdown(void);
void  clientStartup(void);
void *clientThread(void *data);


#endif // CLIENT_H
