コード例 #1
0
    /*long Millisecs(){
     *      return (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;
     * }*/

    private void cmdUser()
    {
        var time = DateTime.Now;
        var dt   = time - sessionTime;

        // если ещё нет сессии или она устарела (> 10 мин)
        if (sessionId.IsNullOrWhiteSpace() || dt.TotalMinutes > 10f)
        {
            sessionId   = SessionCodeGenerator.RandomAbc(16);
            sessionTime = time;
            WriteSessionPrefs(false);
            Log.Galaxy("galaxy. generate new session id");
        }
        // USER <user_id> <user_password> <user_nick> <session_code> [<auth_code>]
        const string commandFormat = "USER {0} {1} {2} {3} {4}";
        var          loginCommand  = string.Format(commandFormat,
                                                   userId,
                                                   userPass,
                                                   userName,
                                                   authCode,
                                                   sessionId);

        SendToServer(loginCommand);
    }