Beispiel #1
0
        /// <summary>
        /// Returns the realm, specified by the next word or number, if the Realm could be found, else sends a reply.
        /// </summary>
        /// <param name="trigger"></param>
        /// <returns></returns>
        public static RealmEntry GetRealm(CmdTrigger <AuthServerCmdArgs> trigger)
        {
            var  arg = trigger.Text.Remainder;
            uint no;
            var  count = AuthenticationServer.RealmCount;

            if (count > 0)
            {
                if (uint.TryParse(arg, out no))
                {
                    if (count < no)
                    {
                        trigger.Reply("Invalid Realm Number - Must be between 1 and {0}", count);
                    }
                    else
                    {
                        return(AuthenticationServer.GetRealmByNumber((int)no));
                    }
                }
                else
                {
                    return(AuthenticationServer.GetRealmByName(arg));
                }
            }
            else
            {
                trigger.Reply("There are no registered Realms.");
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Registers a realm server with the authentication server
        /// </summary>
        /// <param name="realmName">the name of the server</param>
        /// <param name="serverType">the type of the server</param>
        /// <param name="flags">the up/down status of the serer (green/red)</param>
        /// <param name="serverCategory">the timezone the server is in</param>
        /// <param name="serverStatus">the status of the server (locked or not)</param>
        public void RegisterRealmServer(string realmName, string addr, int port, int chrCount, int capacity,
                                        RealmServerType serverType, RealmFlags flags, RealmCategory serverCategory,
                                        RealmStatus serverStatus, ClientVersion clientVersion)
        {
            var context = OperationContext.Current;

            if (context == null)
            {
                return;
            }

            var channel = context.Channel;

            if (channel == null)
            {
                return;
            }

            var id    = GetCurrentId();
            var realm = AuthenticationServer.GetRealmById(id);
            var ep    = GetCurrentEndPoint();

            // find out whether this server is just re-registering (came back online)
            var isNew = realm == null;

            if (isNew)
            {
                realm = AuthenticationServer.GetRealmByName(realmName);
                if (realm == null)
                {
                    if (!AuthServerConfiguration.RealmIPs.Contains(ep.Address))
                    {
                        // Ignore unknown realms
                        log.Warn("Unallowed Realm (\"{0}\") tried to register from: {1} (For more info, see the <RealmIPs> entry in your configuration)",
                                 realmName, ep.Address, AuthServerConfiguration.Instance.FilePath);
                        var chan = OperationContext.Current.Channel;
                        if (chan != null)
                        {
                            try
                            {
                                chan.Close();
                            }
                            catch (Exception) {}
                        }
                        return;
                    }
                    realm = new RealmEntry();
                }
                else
                {
                    lock (AuthenticationServer.Realms)
                    {
                        AuthenticationServer.RemoveRealmByName(realmName);
                    }
                }
            }

            if (string.IsNullOrEmpty(addr))
            {
                // no host given
                addr = ep.Address;
            }

            realm.ChannelId     = id;
            realm.Name          = realmName;
            realm.Address       = addr;
            realm.Port          = port;
            realm.Flags         = flags;
            realm.Status        = serverStatus;
            realm.ServerType    = serverType;
            realm.Category      = serverCategory;
            realm.CharCount     = chrCount;
            realm.CharCapacity  = capacity;
            realm.ClientVersion = clientVersion;

            realm.Channel        = channel;
            realm.ChannelAddress = ep.Address;
            realm.ChannelPort    = ep.Port;


            if (isNew)
            {
                // register after setting all infos
                lock (AuthenticationServer.Realms)
                {
                    AuthenticationServer.AddRealm(realm);
                }
            }
            log.Info(resources.RealmRegistered, realm);             //realm.ChannelAddress);
        }