00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 5 -*- */ 00002 00003 /* 00004 * Combination of a first person action and a real time strategy battle game. 00005 */ 00006 00007 /* 00008 * Network.h 00009 * MetalWarriors 00010 * $Revision: 1.18 $ 00011 * 00012 * Created by Daniel Aarno on Sun Oct 12 2003. 00013 * Copyright (c) 2003 Daniel Aarno and Erik Ytterberg - All rights reserved. 00014 * 00015 * This program is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License as published by 00017 * the Free Software Foundation; either version 2 of the License, or 00018 * (at your option) any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program; if not, write to the Free Software 00027 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 */ 00029 00030 #ifndef _NETWORK_ 00031 #define _NETWORK_ 00032 00033 #include "Packet.h" 00034 #include <string> 00035 00036 #define HAS_NETWORK (Network::HasNetwork()) 00037 00038 enum { 00039 MSG_STRING = 1001 00040 }; 00041 00042 typedef struct { 00043 long msg; 00044 long len; 00045 long error; 00046 long checksum; 00047 } MsgHead; 00048 00049 class Network 00050 { 00051 public: 00052 typedef Packet::uri_t uri_t; 00053 00054 private: 00055 static bool server; 00056 static bool running; 00057 00058 private: 00059 Network(); 00060 00061 public: 00062 virtual ~Network() {} 00063 00064 static void SendMessage(const Packet &p, bool reliable = false); 00065 00066 static Packet GetNextEvent(); 00067 00068 static void Flush(); 00069 00070 static void RequestURIs(int num = 100, bool force = false); 00071 00072 static uri_t GetURI(); 00073 00074 inline static bool HasNetwork() { return running; } 00075 inline static bool IsServer() { return server; } 00076 00077 static bool Start(int port, const std::string &host = ""); 00078 static void Stop(); 00079 static int GetURICount(); 00080 static void ClearURIs(); 00081 static void AddURIRange(int start, int stop); 00082 static void URIReInit(); 00083 static void PrintURIRanges(); 00084 00085 protected: 00086 static void* RecvThread(void* arg); 00087 static void SendMessage(const std::string &msg, bool reliable); 00088 static bool FilterMessage(Packet &p); 00089 }; 00090 00091 #endif
1.4.7