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

« back to all changes in this revision

Viewing changes to server/classes/Link.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
/* Copyright (C) 2000-2004  Thomas Bopp, Thorsten Hampel, Ludger Merkens
 
2
 *
 
3
 *  This program is free software; you can redistribute it and/or modify
 
4
 *  it under the terms of the GNU General Public License as published by
 
5
 *  the Free Software Foundation; either version 2 of the License, or
 
6
 *  (at your option) any later version.
 
7
 *
 
8
 *  This program is distributed in the hope that it will be useful,
 
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *  GNU General Public License for more details.
 
12
 *
 
13
 *  You should have received a copy of the GNU General Public License
 
14
 *  along with this program; if not, write to the Free Software
 
15
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
16
 * 
 
17
 * $Id: Link.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $
 
18
 */
 
19
 
 
20
constant cvs_version="$Id: Link.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $";
 
21
 
 
22
//! A Link points to some other object inside the sTeam system.
 
23
 
 
24
inherit "/classes/Object";
 
25
 
 
26
#include <macros.h>
 
27
#include <exception.h>
 
28
#include <classes.h>
 
29
#include <types.h>
 
30
#include <database.h>
 
31
 
 
32
static object oLinkObject;
 
33
 
 
34
static void
 
35
init()
 
36
{
 
37
    ::init();
 
38
    add_data_storage(STORE_LINK, retrieve_link_data, restore_link_data);
 
39
}
 
40
 
 
41
/**
 
42
 * Create a duplicate of this link object which means create
 
43
 * another link pointing to the same object than this.
 
44
 *  
 
45
 * @return the duplicated object.
 
46
 * @author <a href="mailto:astra@upb.de">Thomas Bopp</a>) 
 
47
 */
 
48
object duplicate()
 
49
{
 
50
    object dup_obj = ::duplicate();
 
51
    dup_obj->set_link_object(oLinkObject);
 
52
    return dup_obj;
 
53
}
 
54
 
 
55
static void delete_object()
 
56
{
 
57
  ::delete_object();
 
58
  if ( objectp(oLinkObject) )
 
59
    oLinkObject->remove_reference(this());
 
60
}
 
61
 
 
62
static void 
 
63
create_object() 
 
64
{
 
65
    oLinkObject   = 0;
 
66
}
 
67
 
 
68
 
 
69
 
 
70
/**
 
71
 * Set the link object which is the object this link refers to.
 
72
 *  
 
73
 * @param obj - the link
 
74
 * @author Thomas Bopp 
 
75
 * @see query_link_object
 
76
 */
 
77
final void
 
78
set_link_object(object obj)
 
79
{
 
80
    if ( objectp(oLinkObject) || !objectp(obj) )        
 
81
        return; // only set link once !
 
82
    /* the object links to another one now */
 
83
    oLinkObject = obj;
 
84
    oLinkObject->add_reference(this());
 
85
    require_save(STORE_LINK);
 
86
}
 
87
 
 
88
/**
 
89
 * Get the object this link points to.
 
90
 *  
 
91
 * @return the object linked to this
 
92
 * @author Thomas Bopp 
 
93
 * @see set_link_object
 
94
 */
 
95
final object
 
96
get_link_object()
 
97
{
 
98
    return oLinkObject;
 
99
}
 
100
 
 
101
/**
 
102
 * Retrieve the to be saved data of this Link.
 
103
 *  
 
104
 * @return mapping of link data.
 
105
 * @author Thomas Bopp (astra@upb.de) 
 
106
 */
 
107
final mapping
 
108
retrieve_link_data()
 
109
{
 
110
    if ( CALLER != _Database )
 
111
        THROW("Caller is not database !", E_ACCESS);
 
112
    return ([ "LinkObject": oLinkObject ]);
 
113
}
 
114
 
 
115
/**
 
116
 * Restore the saved link data. Called by database to load the link.
 
117
 *  
 
118
 * @param mixed data - the data to be restored.
 
119
 * @author Thomas Bopp (astra@upb.de) 
 
120
 */
 
121
final void
 
122
restore_link_data(mixed data)
 
123
{
 
124
    if ( CALLER != _Database )
 
125
        THROW("Caller is not database !", E_ACCESS);
 
126
    if ( arrayp(data) )
 
127
        oLinkObject = data[0];
 
128
    else
 
129
        oLinkObject = data["LinkObject"];
 
130
}
 
131
 
 
132
 
 
133
/**
 
134
 * Get the action to take for this link. Usually follow for exits
 
135
 * or get if the link points to a document.
 
136
 *  
 
137
 * @return the link action string description.
 
138
 * @author <a href="mailto:astra@upb.de">Thomas Bopp</a>) 
 
139
 */
 
140
string get_link_action() 
 
141
{
 
142
    if ( !objectp(oLinkObject) )
 
143
        return "none";
 
144
    else if ( oLinkObject->get_object_class() & 
 
145
      (CLASS_CONTAINER|CLASS_ROOM|CLASS_EXIT|CLASS_MESSAGEBOARD|CLASS_DOCEXTERN) )
 
146
        return "follow";
 
147
    else
 
148
        return "get";
 
149
}
 
150
 
 
151
 
 
152
/**
 
153
 * Get the content size of the object linked to.
 
154
 *  
 
155
 * @return the content size of the linked object.
 
156
 * @author <a href="mailto:astra@upb.de">Thomas Bopp</a>) 
 
157
 */
 
158
int get_content_size()
 
159
{
 
160
    if ( objectp(oLinkObject) ) {
 
161
        if ( !(oLinkObject->get_object_class() & CLASS_LINK) )
 
162
            return oLinkObject->get_content_size();
 
163
    }
 
164
    return ::get_content_size();
 
165
}
 
166
 
 
167
array stat()
 
168
{
 
169
  array stat;
 
170
  if ( objectp(oLinkObject) ) 
 
171
    stat = oLinkObject->stat();
 
172
  else
 
173
    stat = ::stat();
 
174
  return stat;
 
175
}
 
176
 
 
177
int get_object_class() { return CLASS_LINK | ::get_object_class(); }
 
178
 
 
179
 
 
180
 
 
181
 
 
182
 
 
183