corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
4 *
5 * - Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using OpenMetaverse.StructuredData;
29  
30 namespace OpenMetaverse
31 {
32 /// <summary>
33 ///
34 /// </summary>
35 [Flags]
36 public enum PermissionMask : uint
37 {
38 None = 0,
39 Transfer = 1 << 13,
40 Modify = 1 << 14,
41 Copy = 1 << 15,
42 Export = 1 << 16,
43 Move = 1 << 19,
44 Damage = 1 << 20,
45 // All does not contain Export, which is special and must be
46 // explicitly given
47 All = (1 << 13) | (1 << 14) | (1 << 15) | (1 << 19)
48 }
49  
50 /// <summary>
51 ///
52 /// </summary>
53 [Flags]
54 public enum PermissionWho : byte
55 {
56 /// <summary></summary>
57 Base = 0x01,
58 /// <summary></summary>
59 Owner = 0x02,
60 /// <summary></summary>
61 Group = 0x04,
62 /// <summary></summary>
63 Everyone = 0x08,
64 /// <summary></summary>
65 NextOwner = 0x10,
66 /// <summary></summary>
67 All = 0x1F
68 }
69  
70 /// <summary>
71 ///
72 /// </summary>
73 [Serializable()]
74 public struct Permissions
75 {
76 public PermissionMask BaseMask;
77 public PermissionMask EveryoneMask;
78 public PermissionMask GroupMask;
79 public PermissionMask NextOwnerMask;
80 public PermissionMask OwnerMask;
81  
82 public Permissions(uint baseMask, uint everyoneMask, uint groupMask, uint nextOwnerMask, uint ownerMask)
83 {
84 BaseMask = (PermissionMask)baseMask;
85 EveryoneMask = (PermissionMask)everyoneMask;
86 GroupMask = (PermissionMask)groupMask;
87 NextOwnerMask = (PermissionMask)nextOwnerMask;
88 OwnerMask = (PermissionMask)ownerMask;
89 }
90  
91 public Permissions GetNextPermissions()
92 {
93 uint nextMask = (uint)NextOwnerMask;
94  
95 return new Permissions(
96 (uint)BaseMask & nextMask,
97 (uint)EveryoneMask & nextMask,
98 (uint)GroupMask & nextMask,
99 (uint)NextOwnerMask,
100 (uint)OwnerMask & nextMask
101 );
102 }
103  
104 public OSD GetOSD()
105 {
106 OSDMap permissions = new OSDMap(5);
107 permissions["base_mask"] = OSD.FromInteger((uint)BaseMask);
108 permissions["everyone_mask"] = OSD.FromInteger((uint)EveryoneMask);
109 permissions["group_mask"] = OSD.FromInteger((uint)GroupMask);
110 permissions["next_owner_mask"] = OSD.FromInteger((uint)NextOwnerMask);
111 permissions["owner_mask"] = OSD.FromInteger((uint)OwnerMask);
112 return permissions;
113 }
114  
115 public static Permissions FromOSD(OSD llsd)
116 {
117 Permissions permissions = new Permissions();
118 OSDMap map = llsd as OSDMap;
119  
120 if (map != null)
121 {
122 permissions.BaseMask = (PermissionMask)map["base_mask"].AsUInteger();
123 permissions.EveryoneMask = (PermissionMask)map["everyone_mask"].AsUInteger();
124 permissions.GroupMask = (PermissionMask)map["group_mask"].AsUInteger();
125 permissions.NextOwnerMask = (PermissionMask)map["next_owner_mask"].AsUInteger();
126 permissions.OwnerMask = (PermissionMask)map["owner_mask"].AsUInteger();
127 }
128  
129 return permissions;
130 }
131  
132 public override string ToString()
133 {
134 return String.Format("Base: {0}, Everyone: {1}, Group: {2}, NextOwner: {3}, Owner: {4}",
135 BaseMask, EveryoneMask, GroupMask, NextOwnerMask, OwnerMask);
136 }
137  
138 public override int GetHashCode()
139 {
140 return BaseMask.GetHashCode() ^ EveryoneMask.GetHashCode() ^ GroupMask.GetHashCode() ^
141 NextOwnerMask.GetHashCode() ^ OwnerMask.GetHashCode();
142 }
143  
144 public override bool Equals(object obj)
145 {
146 return (obj is Permissions) ? this == (Permissions)obj : false;
147 }
148  
149 public bool Equals(Permissions other)
150 {
151 return this == other;
152 }
153  
154 public static bool operator ==(Permissions lhs, Permissions rhs)
155 {
156 return (lhs.BaseMask == rhs.BaseMask) && (lhs.EveryoneMask == rhs.EveryoneMask) &&
157 (lhs.GroupMask == rhs.GroupMask) && (lhs.NextOwnerMask == rhs.NextOwnerMask) &&
158 (lhs.OwnerMask == rhs.OwnerMask);
159 }
160  
161 public static bool operator !=(Permissions lhs, Permissions rhs)
162 {
163 return !(lhs == rhs);
164 }
165  
166 public static bool HasPermissions(PermissionMask perms, PermissionMask checkPerms)
167 {
168 return (perms & checkPerms) == checkPerms;
169 }
170  
171 public static readonly Permissions NoPermissions = new Permissions();
172 public static readonly Permissions FullPermissions = new Permissions((uint)PermissionMask.All, (uint)PermissionMask.All,
173 (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All);
174 }
175 }