public IMVU.IDL.Buffer Invoke(object owner, UserSession sess, NameValueCollection p, IContext ictx) { try { call_counter.Count(); int plen = (parameters == null) ? 0 : parameters.Length; object[] args = new object[plen + 1]; if (p.Count != plen) { throw new InvalidOperationException("Wrong number of arguments to method " + name + ": " + "expected " + plen.ToString() + " got " + p.Count.ToString()); } for (int i = 0; i != plen; ++i) { string val = p[parameters[i].name]; if (val == null) { throw new InvalidOperationException("Missing argument " + parameters[i].name + " to method " + name); } args[i + 1] = parameters[i].type.ConvertFromString(val); } args[0] = ictx; object ret = null; try { ret = methodInfo.Invoke(owner, args); } catch (TargetInvocationException tie) { Services.Error(ictx, "TargetInvocationException in " + iname + "." + name); // the inner exception is better than the generic target invocation if (tie.InnerException != null) { throw tie.InnerException; } // if no inner, then re-throw what we have throw; } // todo: verify that the return value matches spec! if (ret != null) { return formatter.Format(ret); } return null; } catch (System.Exception) { error_counter.Count(); throw; } }
public static UserSession Create(IContext ctx, string uName) { int n = 0; UserSession ret = new UserSession(); ret.peerAddress = ctx.PeerAddress; // six hour session lifetime ret.userName = uName; again: ret.sid = "sid:" + Helpers.RandomString(20); ret.UpdateExpiryTime(); Buffer s = Helpers.MarshalFromObject(ret); if (!KeyValueStore.StoreBuffer(ret.sid, s, 0)) { Services.Log("Could not store session (unlikely collision?): ({0}/3) {1}", n, ret.sid); ++n; if (n < 3) { goto again; } Services.Raise("Three session id collisions in a row? Is not possible! {0}", ret.sid); } ret.SetCookie(ctx); return ret; }
public bool ValidateUser(UserSession sess) { if (sess == null) { if (needSession != false || (needPermissions != null && needPermissions.Length > 0)) { return false; } return true; } if (needPermissions != null) { foreach (string s in needPermissions) { if (!sess.HasPermission(s)) { return false; } } } return true; }