Exemple #1
0
        /// return a new signed ticket string
        /// </summary>
        public static string MakeTicket(string eventName, DateTime startTime, double durationMinutes, string seat, Uri serverUrl, string key)
        {
            TimedTicket t = new TimedTicket();

            t.version         = CURRENT_VERSION;
            t.eventName       = eventName;
            t.startTime       = startTime.ToUniversalTime();
            t.durationMinutes = durationMinutes;
            t.seat            = seat;
            t.serverUrl       = serverUrl;
            t.Sign(key);
            return(t.ToString());
        }
        public void OnAuthResponseMessage(NetworkConnection conn, AuthResponseMessage msg)
        {
            if (msg.code == 100)
            {
                if (logger.LogEnabled())
                {
                    logger.LogFormat(LogType.Log, "Authentication Response: {0}", msg.message);
                }
                clientStatus = "Ticket accepted";
                // Invoke the event to complete a successful authentication
                OnClientAuthenticated.Invoke(conn);
            }
            else
            {
                logger.LogFormat(LogType.Error, "Authentication Response: {0}", msg.message);
                clientStatus = String.Format("Ticket rejected ({0})", msg.message);

                // Set this on the client for local reference
                conn.isAuthenticated = false;

                // disconnect the client
                conn.Disconnect();

                // debug/test...
                if (!String.IsNullOrEmpty(getServerKey()))
                {
                    TimedTicket t = new TimedTicket();
                    try {
                        t.Parse(ticketString);
                        t.Sign(getServerKey());
                        string ts = t.ToString();
                        logger.LogFormat(LogType.Error, "Self-sign ticket: {0}", ts);
                    } catch (FormatException e) {
                        logger.LogFormat(LogType.Error, "problem making self-sign ticket: {0}", e);
                    }
                }
            }
        }