Exemplo n.º 1
0
        public override Task UserTextMessage(Murmur.User user, Murmur.TextMessage message)
        {
            var apiUser   = new UserWrapper(SteamListener, WServer, user);
            var destChans = message.channels.Select(x => new ChannelShim(WServer, x)).ToArray();

            return(Task.WhenAll(Plugins.Select(x => x.OnChatMessage(apiUser, destChans, message.text))));
        }
Exemplo n.º 2
0
        public override Task ContextAction(string action, Murmur.User usr, int session, int channelid)
        {
            var apiUser = new Plugins.UserWrapper(SteamListener, Server, usr);

            IServerContextCallback server;

            if (ServerCallbacks.TryGetValue(action, out server))
            {
                return(server.Run(apiUser));
            }

            IChannelContextCallback channel;

            if (ChannelCallbacks.TryGetValue(action, out channel))
            {
                return(channel.Run(apiUser, new Plugins.ChannelShim(Server, channelid)));
            }

            IUserContextCallback user;

            if (UserCallbacks.TryGetValue(action, out user))
            {
                return(user.Run(apiUser, new Plugins.UserShim(SteamListener, Server, session)));
            }

            System.Diagnostics.Trace.WriteLine(action, "Unknown context callback action");
            return(Task.FromResult <object>(null));
        }
Exemplo n.º 3
0
        public override async Task UserStateChanged(Murmur.User user)
        {
            using (var context = await FancyContext.Connect())
                using (var transact = context.Database.BeginTransaction())
                {
                    var current = await context.Logs.Where(x => x.Who.Id == user.userid)
                                  .OrderByDescending(x => x.When).Select(x => x.Where.Id).FirstAsync();

                    if (current != user.channel)
                    {
                        context.Logs.Add(new LogEntry.ChannelSwitched
                        {
                            When = DateTimeOffset.Now,
                            Who  = context.Users.Attach(new User {
                                Id = user.userid
                            }),
                            Where = await context.Channels.SingleAsync(x => x.ServerId == user.channel),
                        });

                        await context.SaveChangesAsync();
                    }

                    transact.Commit();
                }
        }
Exemplo n.º 4
0
        public override async Task UserConnected(Murmur.User user)
        {
            using (var context = await FancyContext.Connect())
                using (var transact = context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    var userNotificationsQuery = from usr in context.Users.Include(x => x.PersistentGuest.Godfathers)
                                                 .Include(x => x.GuestInvite.Inviter).Include(x => x.Membership)
                                                 where usr.Id == user.userid
                                                 join evt in context.Logs.OfType <LogEntry.Connected>() on usr.Id equals evt.Who.Id into connectedEvents
                                                 let lastConnection = connectedEvents.Max(x => x.When)
                                                                      join notific in context.OfflineNotifications on usr.Id equals notific.Recipient.Id into notifications
                                                                      select new { usr, notifications = notifications.Where(x => x.When > lastConnection) };
                    var res = await userNotificationsQuery.SingleAsync();

                    foreach (var notify in res.notifications)
                    {
                        await Server.SendMessage(user.session, notify.Message);
                    }

                    if (res.usr.Membership == null)
                    {
                        var onlineUsers = await Server.GetUsers();

                        var godfathers = res.usr.PersistentGuest?.Godfathers?.Select(x => x.UserId) ?? new[] { res.usr.GuestInvite.Inviter.Id };
                        if (!godfathers.Intersect(onlineUsers.Select(x => x.Value.userid)).Any())
                        {
                            await Server.KickUser(user.session, "Inviter not online.");

                            return;
                        }

                        if (res.usr.GuestInvite != null)
                        {
                            // move guest to inviter
                            var inviter = onlineUsers.Single(x => x.Value.userid == res.usr.GuestInvite.InviterId);
                            user.channel  = inviter.Value.channel;
                            user.suppress = false;
                            await Server.SetState(user);
                        }
                    }

                    context.Logs.Add(new LogEntry.Connected
                    {
                        When  = DateTimeOffset.Now,
                        Who   = res.usr,
                        Where = await context.Channels.SingleAsync(x => x.ServerId == user.channel),
                    });
                    await context.SaveChangesAsync();

                    transact.Commit();
                }
        }
Exemplo n.º 5
0
        public override async Task UserTextMessage(Murmur.User user, Murmur.TextMessage message)
        {
            using (var context = await FancyContext.Connect())
                using (var transact = context.Database.BeginTransaction())
                {
                    User senderEntity = null;
                    if (user.userid > 0)
                    {
                        senderEntity = await context.Users.FindAsync(user.userid);
                    }

                    var qtext = message.text.Replace("&quot;", "\"");
                    var msg   = CommandPattern.Matches(qtext).Cast <Match>().Select(m => m.Value).ToArray();
                    if (message.channels.Any())
                    {
                        if (msg[0] == "@fancy-ng")
                        {
                            await CommandMgr.HandleCommand(SteamListener, Server, user, msg.Skip(1));
                        }

                        if (senderEntity != null)
                        {
                            context.Logs.Add(new LogEntry.ChatMessage
                            {
                                When    = DateTimeOffset.Now,
                                Who     = senderEntity,
                                Where   = await context.Channels.SingleAsync(x => x.ServerId == user.channel),
                                Message = message.text
                            });
                        }
                    }

                    if (senderEntity != null)
                    {
                        var messagesInTheLastSeconds = await context.Logs.OfType <LogEntry.ChatMessage>()
                                                       .Where(x => x.Who.Id == senderEntity.Id && x.When > DbFunctions.AddSeconds(DateTimeOffset.Now, -5)).CountAsync();

                        if (messagesInTheLastSeconds >= 3)
                        {
                            await Server.KickUser(user.session, "Who are you, my evil twin?! [stop spamming]");
                        }
                    }

                    await context.SaveChangesAsync();

                    transact.Commit();
                }
        }
Exemplo n.º 6
0
        public override async Task UserDisconnected(Murmur.User user)
        {
            Model.UserAttribute.CertificateCredentials cc;
            Fancyauth.GuestCredentials.TryRemove(user.userid, out cc);

            using (var context = await FancyContext.Connect())
                using (var transact = context.Database.BeginTransaction())
                {
                    context.Logs.Add(new LogEntry.Disconnected
                    {
                        When = DateTimeOffset.Now,
                        Who  = context.Users.Attach(new User {
                            Id = user.userid
                        }),
                        Where = await context.Channels.SingleAsync(x => x.ServerId == user.channel),
                    });

                    await context.SaveChangesAsync();

                    transact.Commit();
                }
        }
Exemplo n.º 7
0
 public virtual Task ContextAction(string action, Murmur.User usr, int session, int channelid)
 {
     return(NullTask);
 }
Exemplo n.º 8
0
 public override void contextAction(string action, Murmur.User usr, int session, int channelid, Ice.Current current__)
 {
 }
Exemplo n.º 9
0
 public override void getState_async(Murmur.AMD_Server_getState cb__, int session, Ice.Current current__)
 {
     Murmur.User ret__ = new Murmur.User();
     cb__.ice_response(ret__);
 }
Exemplo n.º 10
0
 public Murmur.User getState(int session, _System.Collections.Generic.Dictionary<string, string> context__)
 {
     IceInternal.Outgoing og__ = handler__.getOutgoing("getState", Ice.OperationMode.Idempotent, context__);
     try
     {
         try
         {
             IceInternal.BasicStream os__ = og__.ostr();
             os__.writeInt(session);
         }
         catch(Ice.LocalException ex__)
         {
             og__.abort(ex__);
         }
         bool ok__ = og__.invoke();
         try
         {
             if(!ok__)
             {
                 try
                 {
                     og__.throwUserException();
                 }
                 catch(Murmur.InvalidSessionException)
                 {
                     throw;
                 }
                 catch(Murmur.ServerBootedException)
                 {
                     throw;
                 }
                 catch(Ice.UserException ex__)
                 {
                     throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
                 }
             }
             IceInternal.BasicStream is__ = og__.istr();
             is__.startReadEncaps();
             Murmur.User ret__;
             ret__ = null;
             if(ret__ == null)
             {
                 ret__ = new Murmur.User();
             }
             ret__.read__(is__);
             is__.endReadEncaps();
             return ret__;
         }
         catch(Ice.LocalException ex__)
         {
             throw new IceInternal.LocalExceptionWrapper(ex__, false);
         }
     }
     finally
     {
         handler__.reclaimOutgoing(og__);
     }
 }
Exemplo n.º 11
0
 public void userStateChanged(Murmur.User state, _System.Collections.Generic.Dictionary<string, string> context__)
 {
     IceInternal.Outgoing og__ = handler__.getOutgoing("userStateChanged", Ice.OperationMode.Idempotent, context__);
     try
     {
         try
         {
             IceInternal.BasicStream os__ = og__.ostr();
             if(state == null)
             {
                 Murmur.User tmp__ = new Murmur.User();
                 tmp__.write__(os__);
             }
             else
             {
                 state.write__(os__);
             }
         }
         catch(Ice.LocalException ex__)
         {
             og__.abort(ex__);
         }
         bool ok__ = og__.invoke();
         if(!og__.istr().isEmpty())
         {
             try
             {
                 if(!ok__)
                 {
                     try
                     {
                         og__.throwUserException();
                     }
                     catch(Ice.UserException ex__)
                     {
                         throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
                     }
                 }
                 og__.istr().skipEmptyEncaps();
             }
             catch(Ice.LocalException ex__)
             {
                 throw new IceInternal.LocalExceptionWrapper(ex__, false);
             }
         }
     }
     finally
     {
         handler__.reclaimOutgoing(og__);
     }
 }
Exemplo n.º 12
0
 public static _System.Collections.Generic.Dictionary<int, Murmur.User> read(IceInternal.BasicStream is__)
 {
     int sz__ = is__.readSize();
     _System.Collections.Generic.Dictionary<int, Murmur.User> r__ = new _System.Collections.Generic.Dictionary<int, Murmur.User>();
     for(int i__ = 0; i__ < sz__; ++i__)
     {
         int k__;
         k__ = is__.readInt();
         Murmur.User v__;
         v__ = null;
         if(v__ == null)
         {
             v__ = new Murmur.User();
         }
         v__.read__(is__);
         r__[k__] = v__;
     }
     return r__;
 }
Exemplo n.º 13
0
 public virtual Task UserTextMessage(Murmur.User user, Murmur.TextMessage message)
 {
     return(NullTask);
 }
Exemplo n.º 14
0
 public virtual Task UserStateChanged(Murmur.User user)
 {
     return(NullTask);
 }
Exemplo n.º 15
0
 public virtual Task UserDisconnected(Murmur.User user)
 {
     return(NullTask);
 }
Exemplo n.º 16
0
 public static Murmur.User[] read(IceInternal.BasicStream is__)
 {
     Murmur.User[] v__;
     {
         int szx__ = is__.readAndCheckSeqSize(44);
         v__ = new Murmur.User[szx__];
         for(int ix__ = 0; ix__ < szx__; ++ix__)
         {
             v__[ix__] = new Murmur.User();
             v__[ix__].read__(is__);
         }
     }
     return v__;
 }
Exemplo n.º 17
0
        public override Task UserDisconnected(Murmur.User user)
        {
            var apiUser = new UserWrapper(SteamListener, WServer, user);

            return(Task.WhenAll(Plugins.Select(x => x.OnUserDisconnected(apiUser))));
        }
Exemplo n.º 18
0
 private Ice.AsyncResult<Murmur.Callback_ServerCallback_userStateChanged> begin_userStateChanged(Murmur.User state, _System.Collections.Generic.Dictionary<string, string> ctx__, bool explicitContext__, Ice.AsyncCallback cb__, object cookie__)
 {
     IceInternal.OnewayOutgoingAsync<Murmur.Callback_ServerCallback_userStateChanged> result__ = new IceInternal.OnewayOutgoingAsync<Murmur.Callback_ServerCallback_userStateChanged>(this, __userStateChanged_name, userStateChanged_completed__, cookie__);
     if(cb__ != null)
     {
         result__.whenCompletedWithAsyncCallback(cb__);
     }
     try
     {
         result__.prepare__(__userStateChanged_name, Ice.OperationMode.Idempotent, ctx__, explicitContext__);
         IceInternal.BasicStream os__ = result__.ostr__;
         if(state == null)
         {
             Murmur.User tmp__ = new Murmur.User();
             tmp__.write__(os__);
         }
         else
         {
             state.write__(os__);
         }
         os__.endWriteEncaps();
         result__.send__(true);
     }
     catch(Ice.LocalException ex__)
     {
         result__.exceptionAsync__(ex__);
     }
     return result__;
 }
Exemplo n.º 19
0
 public sealed override void contextAction_async(Murmur.AMD_ServerContextCallback_contextAction cb__, string action, Murmur.User usr, int session, int channelid, Ice.Current current__)
 {
     cb__.ice_response();
     AsyncCompleter(ContextAction(action, usr, session, channelid));
 }
Exemplo n.º 20
0
 public override void read__(IceInternal.BasicStream is__, bool rid__)
 {
     if(rid__)
     {
         /* string myId = */ is__.readTypeId();
     }
     is__.startReadSlice();
     if(c == null)
     {
         c = new Murmur.Channel();
     }
     c.read__(is__);
     {
         int szx__ = is__.readSize();
         is__.startSeq(szx__, 4);
         children = new Murmur.Tree[szx__];
         for(int ix__ = 0; ix__ < szx__; ++ix__)
         {
             IceInternal.ArrayPatcher<Murmur.Tree> spx = new IceInternal.ArrayPatcher<Murmur.Tree>("::Murmur::Tree", children, ix__);
             is__.readObject(spx);
             is__.checkSeq();
             is__.endElement();
         }
         is__.endSeq(szx__);
     }
     {
         int szx__ = is__.readSize();
         is__.startSeq(szx__, 42);
         users = new Murmur.User[szx__];
         for(int ix__ = 0; ix__ < szx__; ++ix__)
         {
             users[ix__] = new Murmur.User();
             users[ix__].read__(is__);
             is__.checkSeq();
             is__.endElement();
         }
         is__.endSeq(szx__);
     }
     is__.endReadSlice();
     base.read__(is__, true);
 }
Exemplo n.º 21
0
 public static Murmur.User[] read(IceInternal.BasicStream is__)
 {
     Murmur.User[] v__;
     {
         int szx__ = is__.readSize();
         is__.startSeq(szx__, 42);
         v__ = new Murmur.User[szx__];
         for(int ix__ = 0; ix__ < szx__; ++ix__)
         {
             v__[ix__] = new Murmur.User();
             v__[ix__].read__(is__);
             is__.checkSeq();
             is__.endElement();
         }
         is__.endSeq(szx__);
     }
     return v__;
 }
Exemplo n.º 22
0
 public sealed override void userStateChanged_async(Murmur.AMD_ServerCallback_userStateChanged cb__, Murmur.User state, Ice.Current current__)
 {
     cb__.ice_response();
     AsyncCompleter(UserStateChanged(state));
 }
Exemplo n.º 23
0
 public static void write(IceInternal.BasicStream os__,
     _System.Collections.Generic.Dictionary<int, Murmur.User> v__)
 {
     if(v__ == null)
     {
         os__.writeSize(0);
     }
     else
     {
         os__.writeSize(v__.Count);
         foreach(_System.Collections.Generic.KeyValuePair<int, Murmur.User> e__ in v__)
         {
             os__.writeInt(e__.Key);
             if(e__.Value == null)
             {
                 Murmur.User tmp__ = new Murmur.User();
                 tmp__.write__(os__);
             }
             else
             {
                 e__.Value.write__(os__);
             }
         }
     }
 }
Exemplo n.º 24
0
 public sealed override void userTextMessage_async(Murmur.AMD_ServerCallback_userTextMessage cb__, Murmur.User state, Murmur.TextMessage message, Ice.Current current__)
 {
     cb__.ice_response();
     AsyncCompleter(UserTextMessage(state, message));
 }
Exemplo n.º 25
0
 public void contextAction(string action, Murmur.User usr, int session, int channelid, _System.Collections.Generic.Dictionary<string, string> context__)
 {
     IceInternal.Outgoing og__ = handler__.getOutgoing("contextAction", Ice.OperationMode.Idempotent, context__);
     try
     {
         try
         {
             IceInternal.BasicStream os__ = og__.ostr();
             os__.writeString(action);
             if(usr == null)
             {
                 Murmur.User tmp__ = new Murmur.User();
                 tmp__.write__(os__);
             }
             else
             {
                 usr.write__(os__);
             }
             os__.writeInt(session);
             os__.writeInt(channelid);
         }
         catch(Ice.LocalException ex__)
         {
             og__.abort(ex__);
         }
         bool ok__ = og__.invoke();
         if(!og__.istr().isEmpty())
         {
             try
             {
                 if(!ok__)
                 {
                     try
                     {
                         og__.throwUserException();
                     }
                     catch(Ice.UserException ex__)
                     {
                         throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
                     }
                 }
                 og__.istr().skipEmptyEncaps();
             }
             catch(Ice.LocalException ex__)
             {
                 throw new IceInternal.LocalExceptionWrapper(ex__, false);
             }
         }
     }
     finally
     {
         handler__.reclaimOutgoing(og__);
     }
 }
Exemplo n.º 26
0
 public Task SetState(Murmur.User state)
 {
     return(FixIce.FromAsyncVoid(state, S.begin_setState, S.end_setState));
 }
Exemplo n.º 27
0
 public override void userDisconnected(Murmur.User state, Ice.Current current__)
 {
 }
Exemplo n.º 28
0
 public static Ice.DispatchStatus userStateChanged___(ServerCallback obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Idempotent, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     Murmur.User state;
     state = null;
     if(state == null)
     {
         state = new Murmur.User();
     }
     state.read__(is__);
     is__.endReadEncaps();
     obj__.userStateChanged(state, current__);
     return Ice.DispatchStatus.DispatchOK;
 }
Exemplo n.º 29
0
 public override void userStateChanged(Murmur.User state, Ice.Current current__)
 {
 }
Exemplo n.º 30
0
 public UserWrapper(Steam.SteamListener steamListener, Wrapped.Server server, Murmur.User user)
     : base(steamListener, server, user.session)
 {
     User = user;
 }
Exemplo n.º 31
0
 public override void setState_async(Murmur.AMD_Server_setState cb__, Murmur.User state, Ice.Current current__)
 {
     cb__.ice_response();
 }
Exemplo n.º 32
0
 public Murmur.User end_getState(Ice.AsyncResult r__)
 {
     IceInternal.OutgoingAsync outAsync__ = (IceInternal.OutgoingAsync)r__;
     IceInternal.OutgoingAsync.check__(outAsync__, this, __getState_name);
     if(!outAsync__.wait__())
     {
         try
         {
             outAsync__.throwUserException__();
         }
         catch(Murmur.InvalidSecretException)
         {
             throw;
         }
         catch(Murmur.InvalidSessionException)
         {
             throw;
         }
         catch(Murmur.ServerBootedException)
         {
             throw;
         }
         catch(Ice.UserException ex__)
         {
             throw new Ice.UnknownUserException(ex__.ice_name(), ex__);
         }
     }
     Murmur.User ret__;
     IceInternal.BasicStream is__ = outAsync__.istr__;
     is__.startReadEncaps();
     ret__ = null;
     if(ret__ == null)
     {
         ret__ = new Murmur.User();
     }
     ret__.read__(is__);
     is__.endReadEncaps();
     return ret__;
 }
Exemplo n.º 33
0
 public static Ice.DispatchStatus contextAction___(ServerContextCallback obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Idempotent, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     string action;
     action = is__.readString();
     Murmur.User usr;
     usr = null;
     if(usr == null)
     {
         usr = new Murmur.User();
     }
     usr.read__(is__);
     int session;
     session = is__.readInt();
     int channelid;
     channelid = is__.readInt();
     is__.endReadEncaps();
     obj__.contextAction(action, usr, session, channelid, current__);
     return Ice.DispatchStatus.DispatchOK;
 }
Exemplo n.º 34
0
 private Ice.AsyncResult<Murmur.Callback_ServerContextCallback_contextAction> begin_contextAction(string action, Murmur.User usr, int session, int channelid, _System.Collections.Generic.Dictionary<string, string> ctx__, bool explicitContext__, Ice.AsyncCallback cb__, object cookie__)
 {
     IceInternal.OnewayOutgoingAsync<Murmur.Callback_ServerContextCallback_contextAction> result__ = new IceInternal.OnewayOutgoingAsync<Murmur.Callback_ServerContextCallback_contextAction>(this, __contextAction_name, contextAction_completed__, cookie__);
     if(cb__ != null)
     {
         result__.whenCompletedWithAsyncCallback(cb__);
     }
     try
     {
         result__.prepare__(__contextAction_name, Ice.OperationMode.Idempotent, ctx__, explicitContext__);
         IceInternal.BasicStream os__ = result__.ostr__;
         os__.writeString(action);
         if(usr == null)
         {
             Murmur.User tmp__ = new Murmur.User();
             tmp__.write__(os__);
         }
         else
         {
             usr.write__(os__);
         }
         os__.writeInt(session);
         os__.writeInt(channelid);
         os__.endWriteEncaps();
         result__.send__(true);
     }
     catch(Ice.LocalException ex__)
     {
         result__.exceptionAsync__(ex__);
     }
     return result__;
 }
Exemplo n.º 35
0
 public static Ice.DispatchStatus setState___(Server obj__, IceInternal.Incoming inS__, Ice.Current current__)
 {
     checkMode__(Ice.OperationMode.Idempotent, current__.mode);
     IceInternal.BasicStream is__ = inS__.istr();
     is__.startReadEncaps();
     Murmur.User state;
     state = null;
     if(state == null)
     {
         state = new Murmur.User();
     }
     state.read__(is__);
     is__.endReadEncaps();
     AMD_Server_setState cb__ = new _AMD_Server_setState(inS__);
     try
     {
         obj__.setState_async(cb__, state, current__);
     }
     catch(_System.Exception ex__)
     {
         cb__.ice_exception(ex__);
     }
     return Ice.DispatchStatus.DispatchAsync;
 }
Exemplo n.º 36
0
 public void ice_response(Murmur.User ret__)
 {
     if(validateResponse__(true))
     {
         try
         {
             IceInternal.BasicStream os__ = this.os__();
             if(ret__ == null)
             {
                 Murmur.User tmp__ = new Murmur.User();
                 tmp__.write__(os__);
             }
             else
             {
                 ret__.write__(os__);
             }
         }
         catch(Ice.LocalException ex__)
         {
             ice_exception(ex__);
         }
         response__(true);
     }
 }
Exemplo n.º 37
0
 async Task IReadModifyWriteObject.Refresh()
 {
     User = await Server.GetState(User.session);
 }
Exemplo n.º 38
0
        public Task HandleCommand(Steam.SteamListener steamListener, Wrapped.Server server, Murmur.User caller, IEnumerable <string> cmd)
        {
            CommandFunc func;

            if (_Commands.TryGetValue(cmd.FirstOrDefault(), out func))
            {
                return(func(new Plugins.UserWrapper(steamListener, server, caller), cmd.Skip(1)));
            }
            else
            {
                return(server.SendMessage(caller.session, "Unknown command"));
            }
        }