00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "FSServer.h"
00027
00028 #include "Battle.h"
00029
00030 #include <stdlib.h>
00031
00032 #ifdef _DEBUG
00033 #define new DEBUG_NEW
00034 class CheckMemLeaks {
00035 public:
00036 CheckMemLeaks() {}
00037 ~CheckMemLeaks() { _CrtDumpMemoryLeaks(); }
00038 };
00039
00040 CheckMemLeaks cml;
00041 #endif
00042
00043 int main (int argc, char * argv[])
00044 {
00045 if (argc != 2)
00046 {
00047 cerr << "usage : fs_server [file]" << endl;
00048 return -1;
00049 }
00050
00051 bool error = false;
00052
00053 {
00054 string HostFile = argv[1];
00055 string FileType = HostFile.substr(HostFile.find_last_of('.'));
00056
00057 TheGame = new Game();
00058 TheGalaxy = new Galaxy();
00059
00060 if (stricmp(FileType.c_str(), ".def") == 0) {
00061 cout << "Loading Defination File" << endl;
00062 if (!TheGame->LoadDefFile(argv[1]))
00063 error = true;
00064
00065 TheGame->InitialSeen();
00066
00067 cout << "Writing XY File" << endl;
00068 if (!error)
00069 TheGame->WriteXYFile();
00070 } else if (stricmp(FileType.c_str(), ".hst") == 0) {
00071 cout << "Loading Host File" << endl;
00072 if (!TheGame->LoadHostFile(argv[1]))
00073 error = true;
00074
00075 cout << "Loading Turns" << endl;
00076 if (!error && !TheGame->LoadTurns())
00077 error = true;
00078
00079 cout << "Processing Turns" << endl;
00080 if (!error && !TheGame->ProcessTurn())
00081 error = true;
00082 } else if (FileType[1] == 'm') {
00083 cout << "Loading player file and orders (.x file)" << endl;
00084 if (!TheGame->LoadPlayerFile(argv[1]))
00085 error = true;
00086
00087 cout << "Writing player orders (.x file)" << endl;
00088 if (!error && !TheGame->GetCurrentPlayer()->SaveXFile())
00089 error = true;
00090
00091 if (!error)
00092 TheGame->GetCurrentPlayer()->TestUndoRedo();
00093
00094 error = true;
00095 } else {
00096 cout << "Unknown file type " << FileType << endl;
00097 error = true;
00098 }
00099
00100 cout << "Writing Host File" << endl;
00101 if (!error && !TheGame->WriteHostFile())
00102 error = true;
00103
00104 cout << "Writing Players Files" << endl;
00105 if (!error && !TheGame->WritePlayerFiles())
00106 error = true;
00107
00108
00109 for (unsigned int i = 0; i < TheGame->GetMessages().size(); ++i)
00110 {
00111 string message = TheGame->GetMessages()[i]->ToString();
00112
00113 cout << message << endl;
00114 }
00115
00116 for (unsigned int j = 1; j <= TheGame->NumberPlayers(); ++j)
00117 {
00118 const Player* p = TheGame->GetPlayer(j);
00119 if (p != NULL) {
00120 for (unsigned int i = 0; i < p->GetMessages().size(); ++i)
00121 {
00122 string message = p->GetMessages()[i]->ToString();
00123
00124 {
00125 cout << "Player(" << Long2String(j) << ")" << endl;
00126 cout << message << endl;
00127 }
00128 }
00129 }
00130 }
00131
00132 Rules::Cleanup();
00133 Component::Cleanup();
00134 Battle::Cleanup();
00135 Ship::Cleanup();
00136 delete TheGalaxy;
00137 delete TheGame;
00138 }
00139
00140 if(error)
00141 return -1;
00142
00143 return 0;
00144 }