2010-03-27 07:09:34 +00:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-04-21 23:13:39 +00:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-27 07:09:34 +00:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_SERVERINTERFACE_H_
|
|
|
|
|
#define _GLEST_GAME_SERVERINTERFACE_H_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "game_constants.h"
|
|
|
|
|
#include "network_interface.h"
|
|
|
|
|
#include "connection_slot.h"
|
|
|
|
|
#include "socket.h"
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using Shared::Platform::ServerSocket;
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class ServerInterface
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
string chatText;
|
|
|
|
|
string chatSender;
|
|
|
|
|
int chatTeamIndex;
|
|
|
|
|
int sourceTeamIndex;
|
|
|
|
|
|
|
|
|
|
} TeamMessageData;
|
|
|
|
|
|
|
|
|
|
class ServerInterface: public GameNetworkInterface{
|
|
|
|
|
private:
|
|
|
|
|
ConnectionSlot* slots[GameConstants::maxPlayers];
|
|
|
|
|
ServerSocket serverSocket;
|
|
|
|
|
bool gameHasBeenInitiated;
|
|
|
|
|
int gameSettingsUpdateCount;
|
2010-04-28 23:59:37 +00:00
|
|
|
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ServerInterface();
|
|
|
|
|
virtual ~ServerInterface();
|
|
|
|
|
|
|
|
|
|
virtual Socket* getSocket() {return &serverSocket;}
|
|
|
|
|
virtual const Socket* getSocket() const {return &serverSocket;}
|
|
|
|
|
virtual void close();
|
|
|
|
|
|
|
|
|
|
//message processing
|
|
|
|
|
virtual void update();
|
|
|
|
|
virtual void updateLobby(){};
|
|
|
|
|
virtual void updateKeyframe(int frameCount);
|
|
|
|
|
virtual void waitUntilReady(Checksum* checksum);
|
|
|
|
|
|
|
|
|
|
// message sending
|
|
|
|
|
virtual void sendTextMessage(const string &text, int teamIndex);
|
|
|
|
|
virtual void quitGame(bool userManuallyQuit);
|
|
|
|
|
|
|
|
|
|
//misc
|
|
|
|
|
virtual string getNetworkStatus() const;
|
|
|
|
|
|
|
|
|
|
ServerSocket* getServerSocket() {return &serverSocket;}
|
2010-04-28 23:59:37 +00:00
|
|
|
|
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
2010-03-27 07:09:34 +00:00
|
|
|
|
void addSlot(int playerIndex);
|
2010-04-30 01:08:29 +00:00
|
|
|
|
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
|
2010-03-27 07:09:34 +00:00
|
|
|
|
void removeSlot(int playerIndex);
|
|
|
|
|
ConnectionSlot* getSlot(int playerIndex);
|
|
|
|
|
int getConnectedSlotCount();
|
2010-05-12 15:25:56 +00:00
|
|
|
|
int getOpenSlotCount();
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
bool launchGame(const GameSettings* gameSettings);
|
|
|
|
|
virtual void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck = false);
|
2010-04-21 23:13:39 +00:00
|
|
|
|
void broadcastGameSetup(const GameSettings* gameSettings);
|
2010-05-12 15:25:56 +00:00
|
|
|
|
void updateListen();
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);
|
|
|
|
|
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
2010-05-04 02:32:43 +00:00
|
|
|
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
2010-03-27 07:09:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|