]> jfr.im git - irc/gameservirc.git/blame - gameserv/script.cpp
Wrote a loadScript function to take a script in from a file, and redid the dependencies
[irc/gameservirc.git] / gameserv / script.cpp
CommitLineData
22ea56df 1#include "script.h"
0b71e6c2 2#include "extern.h"
3#include <fstream>
4#include <string>
5
6using namespace std;
22ea56df 7
8script::script()
9{
10 scriptstr = "";
11}
12
13script::script(string &str)
14{
15 scriptstr = str;
16}
17
18script::script(const char *str)
19{
20 scriptstr = str;
21}
22
23script::~script()
24{
25 scriptstr = "";
26}
27
28void script::setString(string &str)
29{
30 scriptstr = str;
31}
32
33void script::setString(const char *str)
34{
35 scriptstr = str;
36}
37
38bool script::executeScript(Player *p)
39{
40 return true;
41}
0b71e6c2 42
43bool script::loadScript(const char *filename)
44{
45 char *buffer;
46 int length;
47 ifstream infile;
48 bool result;
49
50 infile.open(filename, ios::binary);
51
52 if (infile.fail())
53 {
54 log("Error opening script %s", filename);
55 return false;
56 }
57
58 // get length of file:
59 infile.seekg (0, ios::end);
60 length = infile.tellg();
61 infile.seekg (0, ios::beg);
62
63 if (length > 0)
64 {
65 buffer = new char[length];
66 infile.read(buffer, length);
67 scriptstr = buffer;
68 delete [] buffer;
69 result = true;
70 }
71 else
72 {
73 result = false;
74 }
75 infile.close();
76 return result;
77}