~ubuntu-branches/ubuntu/natty/steam/natty

« back to all changes in this revision

Viewing changes to server/classes/Shadow.pike

  • Committer: Bazaar Package Importer
  • Author(s): Alain Schroeder
  • Date: 2005-05-14 16:33:35 UTC
  • Revision ID: james.westby@ubuntu.com-20050514163335-5v7lbxibmlww15dx
Tags: upstream-1.6.3
ImportĀ upstreamĀ versionĀ 1.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
inherit "/classes/Object";
 
2
 
 
3
#include <macros.h>
 
4
 
 
5
static int    iRemote_ObjectID; // the id of the remote object
 
6
static string sRemote_ServerID; // the remote server the object is located
 
7
static int              iLocal; 
 
8
static int     iTemporary = -1;
 
9
static function fExecuteRemote;
 
10
 
 
11
static mapping fTableRemote = ([ ]);
 
12
 
 
13
 
 
14
void set_remote_ObjectID(int objectID)
 
15
{
 
16
    iRemote_ObjectID = objectID;
 
17
    write(sprintf("\nSet_remote_ObjectID to: %d\n",iRemote_ObjectID));
 
18
    require_save();
 
19
}
 
20
 
 
21
void set_remote_ServerID(string serverID) 
 
22
{
 
23
    sRemote_ServerID = serverID;
 
24
    require_save();
 
25
}
 
26
 
 
27
int get_remote_ObjectID() 
 
28
{
 
29
    return iRemote_ObjectID;
 
30
}
 
31
 
 
32
string get_remote_ServerID() 
 
33
{
 
34
    return sRemote_ServerID;
 
35
}
 
36
 
 
37
int set_temporary() 
 
38
{
 
39
    iTemporary = 1;
 
40
    write("Shadow.pike: set_temporary!\n");
 
41
    return iTemporary;
 
42
}
 
43
 
 
44
mixed `[](mixed index) 
 
45
{
 
46
    mixed m;
 
47
    if (is_local()==0)
 
48
    {
 
49
        if (m = fTableRemote[index]) {
 
50
            return m;
 
51
        }
 
52
        else {
 
53
            fTableRemote[index] = getlambda(index);
 
54
            return fTableRemote[index];
 
55
        }
 
56
    }
 
57
    write("\nShadow> Failed Indexing: "+ index +"\n");
 
58
    return 0;
 
59
}
 
60
 
 
61
function getlambda (string fname) 
 
62
{
 
63
    return  lambda (mixed args) {  
 
64
        return remote_call(fname, args); 
 
65
    };
 
66
}
 
67
 
 
68
 
 
69
static mixed remote_call(string fname, mixed args) 
 
70
{
 
71
    write( sIdentifier + "("+ iObjectID +")" + ": remote_call on: ");
 
72
    write(sprintf("%d@%s",iRemote_ObjectID, sRemote_ServerID));
 
73
    write("\n");
 
74
 
 
75
    mixed result = fExecuteRemote(this_user(), iRemote_ObjectID,
 
76
                                  sRemote_ServerID, fname, args);
 
77
    if (!result) {
 
78
        write("\nShadow: Kein Result!\n");
 
79
        return 0;
 
80
    }
 
81
    else {
 
82
        return result;
 
83
    }
 
84
    object cluster = get_module("Cluster");
 
85
    if ( objectp(cluster) )
 
86
        return cluster->send_command(
 
87
            sRemote_ServerID, iRemote_ObjectID, fname, args);
 
88
    steam_error("Failed to locate server cluster.");
 
89
}
 
90
 
 
91
int is_local() 
 
92
{
 
93
    return iLocal;
 
94
}
 
95
 
 
96
bool is_shadow() 
 
97
{
 
98
    return true;
 
99
}
 
100