ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/CGIRenegadeMapSelector/MapSelector.cpp
Revision: 137
Committed: 2003-04-14T19:42:11-07:00 (19 years, 9 months ago) by douglas
File size: 2176 byte(s)
Log Message:
Did stuff!

File Contents

# Content
1 // Renegade Map Selector
2 //
3 // Douglas Thrift
4 //
5 // MapSelector.cpp
6
7 #include "MapSelector.h"
8 #include <unistd.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/param.h>
12 #include <dirent.h>
13
14 MapSelector::MapSelector()
15 {
16 session = 0;
17
18 vector<FormEntry> result;
19 if (cgi.getElement("session", result))
20 {
21 session = result[result.size() - 1].getIntegerValue();
22 result.clear();
23 }
24
25 session = load(session);
26 if (debug)
27 {
28 cerr << "session = " << session << "\navailable = {\n";
29
30 for (unsigned index = 0; index < available.size(); index++)
31 {
32 cerr << " [" << index << "] = " << available[index] << "\n";
33 }
34
35 cerr << "}\nselected = {\n";
36
37 for (unsigned index = 0; index < selected.size(); index++)
38 {
39 cerr << " [" << index << "] = " << selected[index] << "\n";
40 }
41
42 cerr << "}\n";
43 }
44
45 string button;
46 if (cgi.getElement("button", result))
47 {
48 button = result[result.size() - 1].getValue();
49 result.clear();
50 }
51
52 select(button);
53 }
54
55 long MapSelector::load(long session)
56 {
57 if (session == 0)
58 {
59 ifstream fin("mapselector.cfg");
60
61 while (fin.good())
62 {
63 string name;
64 string value;
65
66 getline(fin, name, '=');
67 getline(fin, value);
68
69 if (name == "server")
70 {
71 server = value;
72 }
73 else if (name == "config")
74 {
75 ini = value;
76 }
77 else if (name == "template")
78 {
79 html = value;
80 }
81 else if (name == "redirect")
82 {
83 redirect = value;
84 }
85 }
86
87 fin.close();
88
89 srandomdev();
90 session = random();
91
92 DIR* dir = opendir((server + "/data").c_str());
93
94 set<string> files;
95 dirent* file;
96 while ((file = readdir(dir)) != NULL)
97 {
98 string name = file->d_name;
99
100 if (name.rfind(".mix") == name.length() - 4)
101 {
102 files.insert(name);
103 }
104 }
105
106 closedir(dir);
107
108 for (set<string>::iterator itor = files.begin(); itor != files.end();
109 itor++)
110 {
111 available.push_back(*itor);
112 }
113
114 char* dot = new char[MAXPATHLEN];
115 getcwd(dot, MAXPATHLEN);
116
117 chdir(server.c_str());
118
119 config = new RenegadeConfig(ini);
120 config->load();
121
122 selected = config->getMaps();
123
124 chdir(dot);
125 delete [] dot;
126 }
127 else
128 {
129 //
130 }
131
132 return session;
133 }
134
135 void MapSelector::select(const string& button)
136 {
137 //
138 }