/[fgs]/fgs/src/roomproc.cc
ViewVC logotype

Diff of /fgs/src/roomproc.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by tps12, Thu Sep 4 02:10:27 2003 UTC revision 1.6 by drysdam, Sat Sep 6 00:15:17 2003 UTC
# Line 4  extern "C" { Line 4  extern "C" {
4  #include "stdinclude.h"  #include "stdinclude.h"
5  #include <errno.h>  #include <errno.h>
6  #include <assert.h>  #include <assert.h>
7    #include <sys/stat.h>
8    #include <sys/types.h>
9    #include <unistd.h>
10    #include <dirent.h>
11  #include "common.h"  #include "common.h"
12  #include "ladder.h"  #include "ladder.h"
13  #include "command.h"  #include "command.h"
# Line 18  extern "C" { Line 22  extern "C" {
22  #include <string>  #include <string>
23  #include <sstream>  #include <sstream>
24  #include <algorithm>  #include <algorithm>
25    #include <iostream>
26    #include <fstream>
27    
28  enum TimeType  enum TimeType
29  {  {
# Line 143  static inline void NotifyOccupants(int r Line 149  static inline void NotifyOccupants(int r
149        NotifyOccupant(r, i->first, (int)c, s);        NotifyOccupant(r, i->first, (int)c, s);
150  }  }
151    
152    int rooms_init()
153    {
154      DIR *dp;
155      struct dirent *d;
156      struct stat buf;
157      std::string roomname;
158      int r, member, admin, silenced, banned;
159      char comma;
160    
161      dp = opendir(room_dir);
162      if(!dp)
163        return 1;
164    
165      while(d = readdir(dp)){
166        std::string s = room_dir;
167        s += "/";
168        s += d->d_name;
169    
170        r = atoi(d->d_name);
171    
172        if((stat(s.c_str(), &buf) == 0) && (S_ISREG(buf.st_mode))) {
173          std::ifstream in(s.c_str(), std::ios::in);
174          if(!in.good())
175            return 1;
176    
177          room rm;
178    
179          in >> roomname;
180    
181          rm.name = roomname;
182    
183          while(in.good()) {
184            in >> std::skipws >> member >> comma;
185            rm.members.push_back(member);
186            std::cout << member;
187            std::cout << "\n";
188            std::cout.flush();
189            if(comma == ';') break;
190          }
191    
192          while(in.good()) {
193            in >> std::skipws >> admin >> comma;
194            rm.admins.push_back(admin);
195            std::cout << admin;
196            std::cout << "\n";
197            std::cout.flush();
198            if(comma == ';') break;
199          }
200    
201          while(in.good()) {
202            in >> std::skipws >> silenced >> comma;
203            rm.silenced.push_back(silenced);
204            std::cout << silenced;
205            std::cout << "\n";
206            std::cout.flush();
207            if(comma == ';') break;
208          }
209    
210          while(in.good()) {
211            in >> std::skipws >> banned >> comma;
212            rm.banned.push_back(banned);
213            std::cout << banned;
214            std::cout << "\n";
215            std::cout.flush();
216            if(comma == ';') break;
217          }
218    
219          rarray.insert(std::pair<int, room>(r, rm));
220    
221        }
222      }
223      return 0;
224    }
225    
226    int SaveRoom(int r)
227    {
228      // lookup room
229      std::map<int, room>::iterator rmi = rarray.find(r);
230      if(rmi == rarray.end()) return COM_NOSUCHROOM;
231      room& rm = rmi->second;
232    
233      std::stringstream ss;
234      ss << r;
235      std::string fname = room_dir;
236      fname += "/";
237      fname += ss.str();
238      std::ofstream out(fname.c_str(), std::ios::out|std::ios::trunc);
239      
240      if(!out.good())
241        return COM_NOTIFYADMIN;
242    
243      out << rm.name;
244      //  out << "\nMembers\n";
245      out << "\n";
246    
247      for(std::vector<int>::iterator i = rm.members.begin();
248          i != rm.members.end(); ++i) {
249        out << *i;
250        std::vector<int>::iterator j = i;
251        if(++j != rm.members.end()) out << ", ";
252      }
253    
254      //  out << "\nAdmins\n";
255      out << "\n";
256    
257      for(std::vector<int>::iterator i = rm.admins.begin();
258          i != rm.admins.end(); ++i) {
259        out << *i;
260        std::vector<int>::iterator j = i;
261        if(++j != rm.admins.end()) out << ", ";
262      }
263    
264      //  out << "\nSilenced\n";
265      out << "\n";
266    
267      for(std::vector<int>::iterator i = rm.silenced.begin();
268          i != rm.silenced.end(); ++i) {
269        out << *i;
270        std::vector<int>::iterator j = i;
271        if(++j != rm.silenced.end()) out << ", ";
272      }
273    
274      //  out << "\nBanned\n";
275      out << "\n";
276    
277      for(std::vector<int>::iterator i = rm.banned.begin();
278          i != rm.banned.end(); ++i) {
279        out << *i;
280        std::vector<int>::iterator j = i;
281        if(++j != rm.banned.end()) out << ", ";
282      }
283    
284      out.close();
285    
286      return COM_OK;
287    
288    }
289    
290  int clear_player_from_rooms(int p)  int clear_player_from_rooms(int p)
291  {  {
292    //check all the rooms for this player and send    //check all the rooms for this player and send
# Line 168  int com_roomjoin(int p, param_list param Line 312  int com_roomjoin(int p, param_list param
312    std::map<int, room>::iterator rmi = rarray.find(r);    std::map<int, room>::iterator rmi = rarray.find(r);
313    if(rmi == rarray.end()) return COM_NOSUCHROOM;    if(rmi == rarray.end()) return COM_NOSUCHROOM;
314    room& rm = rmi->second;    room& rm = rmi->second;
315      // only allow registered users to join
316      if(!parray[p].registered) return COM_NOTREGISTERED;
317    // only allow visitors to join    // only allow visitors to join
318    std::map<int, occupant>::iterator res = rm.occupants.find(p);    std::map<int, occupant>::iterator res = rm.occupants.find(p);
319    if(res == rm.occupants.end()) return COM_NOTINROOM;    if(res == rm.occupants.end()) return COM_NOTINROOM;
# Line 175  int com_roomjoin(int p, param_list param Line 321  int com_roomjoin(int p, param_list param
321    res->second.member = true;    res->second.member = true;
322    ReplyOccupant(r, p, ROOM + Join, parray[p].name);    ReplyOccupant(r, p, ROOM + Join, parray[p].name);
323    NotifyOccupants(r, ROOM + Join, parray[p].name, p);    NotifyOccupants(r, ROOM + Join, parray[p].name, p);
324    return COM_OK;  
325      return SaveRoom(r);
326  }  }
327    
328  int com_roomunjoin(int p, param_list param)  int com_roomunjoin(int p, param_list param)
# Line 290  int com_roomcreate(int p, param_list par Line 437  int com_roomcreate(int p, param_list par
437      ;      ;
438    rarray[r].name = s;    rarray[r].name = s;
439    ReplyOccupant(r, p, ROOM + Create, s);    ReplyOccupant(r, p, ROOM + Create, s);
440    return COM_OK;  
441      return SaveRoom(r);
442  }  }
443    
444  int com_roomlistoccupants(int p, param_list param)  int com_roomlistoccupants(int p, param_list param)
# Line 320  int com_roomlistrooms(int p, param_list Line 468  int com_roomlistrooms(int p, param_list
468        i != rarray.end(); ++i) {        i != rarray.end(); ++i) {
469      std::string s = rarray[i->first].name;      std::string s = rarray[i->first].name;
470      std::map<int, room>::iterator j = i;      std::map<int, room>::iterator j = i;
471      if(++j != rarray.end()) s += "\n";      if(++j != rarray.end()) s += "\n";
472      pprintf(p, "%d %d %s", ROOM + ListRoom, i->first, s.c_str());      pprintf(p, "%d %d %s", ROOM + ListRoom, i->first, s.c_str());
473    }    }
474    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26