jackba / wy-internal-system

Automatically exported from code.google.com/p/wy-internal-system
0 stars 0 forks source link

pricing for the system #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
as title

Original issue reported on code.google.com by Giggs...@gmail.com on 13 Feb 2012 at 7:31

GoogleCodeExporter commented 9 years ago
//xxx=aaa,bbbb,cccc
//sStartWord="xxx=",delim=","
//
static bool Split(const string sStartWord, const string sSrc, string *&out, 
int& count, int limitCount, const char *delim)
{
    //make a copy of src
    //
    int len = sSrc.length();
    if (len == 0)
    {
        return false;
    }
    char *src = new char[len + 1];
    ZeroMemory(src, len + 1);
    memcpy(src, sSrc.c_str(), len);

    //check count
    //
    count = 1;
    for (int k = 0; k < strlen(src); k++)
    {
        if (*(src + k) == *delim)
        {
            count++;
        }
    }
    out = new string[count];
    for (int m = 0; m < count; m++)
    {
        out[m] = "";
    }
    if (limitCount != -1)   //no limit
    {
        if (count > limitCount)
        {
            delete src;
            delete out;
            return false;
        }
    }

    int index = 0;
    char *p = NULL;
    if (sStartWord.length() > 0)
    {
        index = sStartWord.length();
        if (index < 0)
        {
            delete src;
            delete out;
            return false;
        }
        index += 1;
    }
    p = strtok(src + index, delim);
    int i = 0;
    out[i] = p;
    //::MessageBox(NULL, p, "LOB", MB_OK);  //test
    while((p = strtok(NULL, delim)))
    {
        out[++i] = p;
        //::MessageBox(NULL, p, "LOB", MB_OK);  //test
    }

    delete src;
    return true;
}

Original comment by Giggs...@gmail.com on 1 Jun 2012 at 2:42

GoogleCodeExporter commented 9 years ago
#include <string.h>
#include <stdio.h>

static bool write = false;

struct man
{
    char name[20];
    int age;
    char *info;
    int infoLen;
};

void main()
{
    FILE *fp = NULL;

    if (write)
    {
        man m[4];
        memset(m, 0, sizeof(man) * 4);

        long len = sizeof(long);

        for (int i = 0; i < 4; i++)
        {
            strcat(m[i].name, "Jason&Ray");
            m[i].age = 19;
            m[i].infoLen = 19;
            m[i].info = new char[19];
            memset(m[i].info, 0, 19);
            strcat(m[i].info, "a handsome boy.");
            len += sizeof(m) + m[i].infoLen;
        }

        char *buffer = new char[len];
        int offset = 0;
        memcpy(buffer + offset, &len, sizeof(long));
        offset += sizeof(long);
        for (int i = 0; i < 4; i++)
        {
            memcpy(buffer + offset, &m[i], sizeof(man));
            offset += sizeof(man);
            memcpy(buffer + offset, m[i].info, m[i].infoLen);
            offset += m[i].infoLen;
        }

        if (NULL != (fp = fopen("C:\\fdb.db","rb+")))
        {
                fwrite((const void *)buffer, len, 1, fp);
        }
            fclose (fp);
    }
    else    //read & print
    {
        if (NULL != (fp = fopen("C:\\fdb.db","rb+")))
        {
            man m[4];
            memset(m, 0, sizeof(man) * 4);

            long len = 0;           
            fread((void *)(&len), sizeof(len), 1, fp);
            if (len < 0)
            {
                printf("no records!\n");
                return;
            }
            char *buffer = new char[len];
            fseek(fp, 0, SEEK_SET);
            fread((void *)(buffer), len, 1, fp);

            long offset = sizeof(len);

            for (int i = 0; i < 4; i++)
            { 
                man *p = (man *)(buffer + offset);
                char *info = buffer + offset + sizeof(man);
                memcpy((void *)(&m[i]), p, sizeof(man));
                offset += sizeof(man);
                m[i].infoLen = p->infoLen;
                m[i].info = new char[p->infoLen];
                memcpy((void *)(m[i].info), info, p->infoLen);
                offset += p->infoLen;
            }

            for (int i = 0; i < 4; i++)
            {
                printf("-%s-  -%d-  -%s-------\n", m[i].name, m[i].age, m[i].info);
            }

            delete buffer;

            fclose (fp);

            getchar();
        }
    }
}

Original comment by Giggs...@gmail.com on 14 Jun 2012 at 4:17

GoogleCodeExporter commented 9 years ago
char *Protocol_PackRequestIssueAnnouncement(structAnnouncement *p, int &len)
{
    structRequestData srd;
    memset((void *)&srd, 0, SIZE_structRequestData);
    srd.dwType = C_REQ_IssueAnnouncement;
    srd.dwLen =  SIZE_structAnnouncement - 4 + p->dwContentLen;

    len = SIZE_structRequestData - 4 + srd.dwLen;
    char *data = new char[len];
    memcpy(data, &srd, SIZE_structRequestData - 4);
    memcpy(data + SIZE_structRequestData - 4, p, SIZE_structAnnouncement - 4);
    memcpy(data + SIZE_structRequestData - 4 + SIZE_structAnnouncement - 4, p->pContent, p->dwContentLen);
    return data;
}

static void HandleIssueAnnouncement(structConnectionInfo *pInfo, char *body, 
DWORD bodyLen, bool &bClientDisconnected)
{
    structAnnouncement *p = new structAnnouncement;
    memcpy(p, body, SIZE_structAnnouncement - 4);
    if (p->dwContentLen + SIZE_structAnnouncement - 4 != bodyLen)
    {
        bClientDisconnected = true;
        return;//danger!
    }
    p->pContent = new char[p->dwContentLen];
    memcpy(p->pContent, body + SIZE_structAnnouncement - 4, p->dwContentLen);
    //add this user's other info, etc.
    //
    char *pHNWCName = astl_GetHNWCName(pInfo->gradeYear, HM_Major[pInfo->major], pInfo->realName, REAL_NAME_LENGTH);
    p->sf_pHNWCName = pHNWCName;
    p->sf_dwHNWCNameLen = strlen(pHNWCName) + 1;
    char *pHNWCPosition = astl_GetHNWCPositionInChineseByIDCard(pInfo->IDCard);
    p->sf_pHNWCPosition = pHNWCPosition;
    p->sf_dwHNWCPositionLen = strlen(pHNWCPosition) + 1;
    //insert into db.
    //...
    CStringA sError = "";
    if (!Logic_AnncmtAddOne(p, pInfo, sError))
    {
        if (m_cbEmergency) m_cbEmergency(DB_ERROR_AddAnnouncement, NULL);
        return;
    }
    //get the ID just inserted
    //
    int announcementID = -1;
    if (!Logic_AnnmtGetMaxID(announcementID))
    {
        if (m_cbEmergency) m_cbEmergency(DB_ERROR_AddAnnouncement, NULL);
        return;
    }
    p->dwKey = announcementID;
    //add to memory
    //...
    ancmt_AppendAnnouncementInMemory(p);
    //return result
    //...
    int len = 0;
    char *data = Protocol_PackResponseIssueAnnouncement(len, HM_ERROR_NONE);
    if (data && len > 0)
    {
        if (!Network_Send(pInfo->sockClient, data, len))
        {
            bClientDisconnected = true;
        }
        delete data;
    }
    //trigger broadcast
    //...
    structBroadcast *pB = new structBroadcast;
    memset(pB, 0, SIZE_structBroadcast);
    pB->bt = BT_ANNOUNCEMENT;
    pB->pData = Protocol_CopyAnnouncement(p);

    Broadcast_Do(pB);
}

Original comment by Giggs...@gmail.com on 20 Jun 2012 at 1:10

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 22 Jun 2012 at 10:22

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
typedef struct _structAnnouncement
{
    char Title[ANNOUNCEMENT_TITLE_LEN + 1];
    char Datetime[DATETIME_length + 1];
    struct_IDCard dwAudienceIDCard;
    DWORD dwKey;
    DWORD dwCountGet;
    DWORD dwCountJoin;
    DWORD dwContentLen;
    char CreatorID[USER_ID_LENGTH + 1];
    enumAnnouncementType eat;
    char *pContent;
    //special fields
    //
    char sf_pHNWCName[ANNOUNCEMENT_HNWC_Name_LEN_LIMIT + 1];
    char sf_pHNWCPosition[ANNOUNCEMENT_HNWC_Position_LEN_LIMIT + 1];
}structAnnouncement;

Original comment by Giggs...@gmail.com on 12 Jul 2012 at 12:31

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 17 Jul 2012 at 4:18

Attachments:

GoogleCodeExporter commented 9 years ago
bool AppendSome(structAnnouncement *p, int count, bool bReset)
{
    char *pBufferToWrite = NULL;
    size_t stLenOld = 0;
    HeaderDB hd;

    size_t stBodyLenNew = 0;
    char *pNew = Structure2Memory(stBodyLenNew, p, count);
    if (!bReset)    //append to current
    {
        if (!ReadFile(m_path, pBufferToWrite, stLenOld, 0))
        {
            //file not exist,so...
            //
            memset(&hd, 0, sizeof(HeaderDB));
            hd.stBodyLen = stBodyLenNew;
            hd.stCount = count;
            hd.stMaxKey = p->dwKey;//1st one??

            pBufferToWrite = new char[sizeof(hd) + hd.stBodyLen];
            memcpy(pBufferToWrite, &hd, sizeof(hd));
            memcpy(pBufferToWrite + sizeof(hd), pNew, hd.stBodyLen);
        }
        else
        {
            //get HeaderDB first
            //
            if (stLenOld < sizeof(HeaderDB))
            {
                return false;
            }
            memcpy(&hd, pBufferToWrite, sizeof(HeaderDB));
            hd.stCount += count;
            hd.stBodyLen += stBodyLenNew;
            hd.stMaxKey = p->dwKey;//??
            memcpy(pBufferToWrite, &hd, sizeof(HeaderDB));

            char *pTotal = new char[stBodyLenNew + stLenOld];
            memcpy(pTotal, pBufferToWrite, stLenOld);
            memcpy(pTotal + stLenOld, pNew, stBodyLenNew);
            delete pBufferToWrite;
            pBufferToWrite = pTotal;
        }
    }
    else
    {               
        memset(&hd, 0, sizeof(HeaderDB));
        hd.stBodyLen = stBodyLenNew;
        hd.stCount = count;
        hd.stMaxKey = p->dwKey;//1st one??

        pBufferToWrite = new char[sizeof(hd) + hd.stBodyLen];
        memcpy(pBufferToWrite, &hd, sizeof(hd));
        memcpy(pBufferToWrite + sizeof(hd), pNew, hd.stBodyLen);
    }

    if (!WriteFile(m_path, pBufferToWrite, sizeof(hd) + hd.stBodyLen))
    {
        DeleteMem(pNew, pBufferToWrite, -1);    
        return false;
    }

    DeleteMem(pNew, pBufferToWrite, -1);    

    return true;
}

Original comment by Giggs...@gmail.com on 17 Jul 2012 at 9:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 25 Jul 2012 at 9:57

Attachments:

GoogleCodeExporter commented 9 years ago
//创建快捷方式 
BOOL CreateLink (LPSTR szPath,LPSTR szLink)/*szPath 
快捷方式的目标应用程序名 
szLink快捷方式的数据文件名(*.lnk) */
{ 
    HRESULT hres ; 
    IShellLink * psl ; 
    IPersistFile* ppf ; 
    WORD wsz[ MAX_PATH] ; 

    ////初始化COM 
    CoInitialize (NULL); 

    //创建一个IShellLink实例 
    hres = CoCreateInstance( CLSID_ShellLink, NULL,CLSCTX_INPROC_SERVER, IID_IShellLink, 
        (void **)&psl) ; 
    if( FAILED( hres)) 
    { 
        CoUninitialize (); 
        return FALSE ; 
    } 

    //设置目标应用程序 
    psl -> SetPath(L"C:\\Giggs\\Project\\PicturedButton\\debug\\PicturedButton.exe") ; 

    //设置快捷键(此处设为Shift+Ctrl+'R') 
    psl -> SetHotkey( MAKEWORD( 'R', HOTKEYF_SHIFT |HOTKEYF_CONTROL)) ; 

    //char* p; 
    //for( p=szPath+strlen(szPath)-1; *p != '//'; p--); 
    //*p='/0'; 
    psl -> SetWorkingDirectory(L"C:\\Giggs\\Project\\PicturedButton\\debug\\"); 

    //从IShellLink获取其IPersistFile接口 
    //用于保存快捷方式的数据文件 (*.lnk) 
    hres = psl -> QueryInterface( IID_IPersistFile, (void**)&ppf) ; 
    if( FAILED( hres)) 
    { 
        CoUninitialize (); 
        return FALSE ; 
    } 

    // 确保数据文件名为ANSI格式 
    MultiByteToWideChar( CP_ACP, 0, szLink, -1, (LPWSTR)wsz, MAX_PATH) ; 

    //调用IPersistFile::Save 
    //保存快捷方式的数据文件 (*.lnk) 
    hres = ppf -> Save((LPWSTR)wsz, STGM_READWRITE); 
    //释放IPersistFile和IShellLink接口 
    ppf -> Release( ) ; 
    psl -> Release( ) ; 
    CoUninitialize (); 
    return TRUE; 
}  

Original comment by Giggs...@gmail.com on 30 Jul 2012 at 9:26

GoogleCodeExporter commented 9 years ago

    ::RegisterHotKey(m_hWnd, 001, MOD_CONTROL, VK_F8);

BOOL CPicturedButtonDlg::PreTranslateMessage(MSG* pMsg)
{
    switch (pMsg->message)
    {
        case WM_HOTKEY:
            if (001 == pMsg->wParam)MessageBox(L"Welcome tohttp://hi.baidu.com/darks00n/");
            break;
        default:
            break;
    }

    return CDialog::PreTranslateMessage(pMsg);
}

Original comment by Giggs...@gmail.com on 30 Jul 2012 at 9:44

GoogleCodeExporter commented 9 years ago
        DWORD WINAPI ServerThreadProc(LPVOID lpParam)
        if (NULL != (m_hServerThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ServerThreadProc, NULL, 0, NULL))

Original comment by Giggs...@gmail.com on 2 Aug 2012 at 12:40

GoogleCodeExporter commented 9 years ago
    HANDLE h = ::CreateMutex(NULL, FALSE, L"HNWC-TSD-HM");
    if (GetLastError() == ERROR_ALREADY_EXISTS)
    {
        AfxMessageBox(L"");
        ::ReleaseMutex(h);
        CloseHandle(h);
        //m_hMutex = NULL;
    }

Original comment by Giggs...@gmail.com on 2 Aug 2012 at 2:42

GoogleCodeExporter commented 9 years ago

CWaitingDlg::CWaitingDlg(bool *pTaskFinished, int iTimeOut, CWnd* pParent) : 
CDialog(CWaitingDlg::IDD, pParent)
{
    m_pTaskFinished = pTaskFinished;
    m_iTimeOut = iTimeOut;
}

BOOL CWaitingDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    SetTimer(TIMER_Waiting, 1000, NULL);

    return TRUE;
}
void CWaitingDlg::OnTimer(UINT_PTR nIDEvent)
{
    if (nIDEvent == TIMER_Waiting)
    {
        static int i = 0;
        if (*m_pTaskFinished == true || m_iTimeOut-- == 0)
        {
            i = 0;
            KillTimer(TIMER_Waiting);
            INT_PTR nResult = 0;
            this->EndDialog(nResult);
        }
        //paint
        //
        if (i % 4 == 0)
        {
            m_staticWait.SetWindowTextW(L"请稍候.../");
        }
        else if (i % 4 == 1)
        {
            m_staticWait.SetWindowTextW(L"请稍候...-");
        }
        else if (i % 4 == 2)
        {
            m_staticWait.SetWindowTextW(L"请稍候...\\");
        }
        else if (i % 4 == 3)
        {
            m_staticWait.SetWindowTextW(L"请稍候...|");
        }
        i++;
    }

    CDialog::OnTimer(nIDEvent);
}

BOOL CWaitingDlg::PreTranslateMessage(MSG* pMsg)
{
    if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE))
    {
        return true;
    }
    if ((pMsg->message == WM_CLOSE))
    {
        return true;
    }

    return CDialog::PreTranslateMessage(pMsg);
}
void CWaitingDlg::OnClose()
{
    // TODO: Add your message handler code here and/or call default

//  CDialog::OnClose();
}

/////////////////////////////////////////
class CWaitingDlg : public CDialog
{
    DECLARE_DYNAMIC(CWaitingDlg)

private:
    CWaitingDlg(CWnd* pParent = NULL);   // standard constructor
    bool *m_pTaskFinished;
    int m_iTimeOut;

public:
    CWaitingDlg(bool *pTaskFinished, int iTimeOut, CWnd* pParent = NULL);
    virtual ~CWaitingDlg();

// Dialog Data
    enum { IDD = IDD_DIALOG_Waiting };

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    virtual BOOL OnInitDialog();
    virtual BOOL PreTranslateMessage(MSG* pMsg);

    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnTimer(UINT_PTR nIDEvent);
public:
    afx_msg void OnClose();
    CStatic m_staticWait;
};
//////////////////////////////////////////trigger
/////////////////////////////////////////////////////////////////////////

DWORD WINAPI ServerThreadProc(LPVOID lpParam)
{
    bool *pTaskFinished = (bool *)lpParam;
    for (int i = 0; i < 10; i++)
    {
        Sleep(1000);
    }

    *pTaskFinished = true;

    return 0;
}
void CPicturedButtonDlg::OnBnClickedButton5()
{
    bool *pTaskFinished = new bool;
    *pTaskFinished = false;
    int iTimeOut = 10;
    HANDLE m_hServerThread = NULL;
    //start the thread
    //...
    if (NULL != (m_hServerThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ServerThreadProc, (LPVOID)pTaskFinished, 0, 0)))
    {
        CWaitingDlg dlg(pTaskFinished, iTimeOut);
        dlg.DoModal();
        CloseHandle(m_hServerThread);
        delete pTaskFinished;
    }
    else
    {
        delete pTaskFinished;
    }
    //popup waiting dialog
    //...
}

Original comment by Giggs...@gmail.com on 2 Aug 2012 at 8:31

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 7 Aug 2012 at 2:13

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
    Log_Init("C:\\");
    for (int i = 0; i < 5000; i++)
    {
        Log_Add("what!sgwa'[egja[pg4ujw3[-w3[-w3[-w3[-w3[-q0gjq3[g4juq04uq304hu9q30hj[aghjawghaspeghaspdyhapthpa9ge8hw", LOGTYPE_DEBUG);
    }
    Log_Fini();

////////////////////////////////////////////////
#include "Log.h"
#include <string.h>

static char m_LogCache[MAX_LOG_CACHE];
static int m_iCurrentPos = 0;
static char *m_dir = "";

void Log_Init(char *dir)
{
    memset(m_LogCache, 0, MAX_LOG_CACHE);
    m_iCurrentPos = 0;
    m_dir = new char[512];
    memset(m_dir, 0, 512);
    memcpy(m_dir, dir, strlen(dir));
}
void Log_Fini()
{
    if (m_dir)
    {
        delete m_dir;
    }
}
void Log_Add(char *p, enumLogType elt)
{
    char szDateTime[19 + 1];
    memset(szDateTime, 0, 19 + 1);
    //...
    memcpy(szDateTime, "2003-03-07 12.22.22", 19);//...

    if (m_iCurrentPos + 3 + 19 + strlen(p) + 2 > MAX_LOG_CACHE)
    {
        static int dirLen = strlen(m_dir);
        memcpy(m_dir + dirLen, szDateTime, 19);
        memcpy(m_dir + dirLen + 19, ".txt", 4);//   m_dir + date_time as .log file name
        WriteFile(m_dir, m_LogCache, m_iCurrentPos);
        m_iCurrentPos = 0;
        memset(m_LogCache, 0, MAX_LOG_CACHE);
    }
    else
    {
        const char *LogTypePrefix[] = {"[I]", "[S]", "[D]"};
        memcpy(m_LogCache + m_iCurrentPos, LogTypePrefix[elt], 3);
        m_iCurrentPos += 3;
        memcpy(m_LogCache + m_iCurrentPos, szDateTime, 19); 
        m_iCurrentPos += 19;
        memcpy(m_LogCache + m_iCurrentPos, p, strlen(p));
        m_iCurrentPos += strlen(p);
        memcpy(m_LogCache + m_iCurrentPos, "\r\n", 2);
        m_iCurrentPos += 2;
    }
}
////////////////////////////////////////////////
#pragma once

#include "HMFile.h"

#define MAX_LOG_CACHE 1024 * 8  //...

typedef enum _enumLogType
{
    LOGTYPE_INFO = 0,
    LOGTYPE_SECURITY,
    LOGTYPE_DEBUG
}enumLogType;

//dir ends with "/"
void Log_Init(char *dir);
void Log_Fini();
void Log_Add(char *p, enumLogType elt);

Original comment by Giggs...@gmail.com on 21 Aug 2012 at 10:13

GoogleCodeExporter commented 9 years ago
#pragma once

typedef struct _structBlackSheetInfo
{
    bool bValid;
    short connection_count;
    unsigned long ip;
}structBlackSheetInfo;

//load the black sheet from db
void BlackSheet_Init();
//write the black sheet to db and free it in memory
void BlackSheet_Fini();
//will reset those not black after a period
bool BlackSheet_Check(unsigned long ip);

//////////////////////////////////.cpp
#include "BlackSheet.h"

#define MAX_BlackSheetCount 1024
#define MAX_ConnectionPerPeriod 36

static int m_currentCount = 0;
static structBlackSheetInfo m_sbsi[MAX_BlackSheetCount];

//load black sheet from db
void BlackSheet_Init()
{
    for (int i = 0; i < MAX_BlackSheetCount; i++)
    {
        m_sbsi[i].bValid = false;
    }
    m_currentCount = 0;
    //load black sheet from db
    //...

    //faked data
    //
    m_currentCount = 54;
    for (int i = 0; i < m_currentCount; i++)
    {
        m_sbsi[i].ip = i;
        m_sbsi[i].bValid = true;
        m_sbsi[i].connection_count = 1;
    }
}
//write the black sheet to db and free it in memory
void BlackSheet_Fini()
{
    //write black ip to db
    //...

    for (int i = 0, j = 0; i < MAX_BlackSheetCount && j < m_currentCount; i++)
    {
        if (m_sbsi[i].bValid)
        {
            m_sbsi[i].bValid = false;
            j++;
        }
    }
    m_currentCount = 0;
}

//will reset those not black after a period
bool BlackSheet_Check(unsigned long ip)
{
    //check period
    //
    //...
    bool bAfterPeriod = true;
    //reset those not black
    if (bAfterPeriod)
    {
        for (int i = 0, j = 0; i < MAX_BlackSheetCount && j < m_currentCount; i++)
        {
            if (m_sbsi[i].bValid)
            {
                if (m_sbsi[i].connection_count < MAX_ConnectionPerPeriod)
                {
                    m_sbsi[i].bValid = false;//delete safe connections
                    m_currentCount--;
                }
            }
        }
    }

    bool bFindThisIP = false;
    for (int i = 0, j = 0; i < MAX_BlackSheetCount && j < m_currentCount; i++)
    {
        if (m_sbsi[i].ip == ip)
        {
            bFindThisIP = true;
            if (m_sbsi[i].connection_count < 0x00FF)//don't let it be too big.It's short type
            {
                m_sbsi[i].connection_count++;   
            }
            if (m_sbsi[i].connection_count > MAX_ConnectionPerPeriod)
            {
                return false;//danger!
            }
            else
            {
                return true;//this ip connection is not frequent,so let it connect to login
            }
        }
    }
    //add this ip
    if (!bFindThisIP)
    {
        for (int i = 0; i < MAX_BlackSheetCount; i++)
        {
            if (!m_sbsi[i].bValid)
            {
                m_sbsi[i].bValid = true;
                m_sbsi[i].connection_count = 0;
                m_sbsi[i].ip = ip;
                m_currentCount++;
                break;
            }
        }
    }
    if (m_currentCount >= MAX_BlackSheetCount)
    {
        //emergency
        //...
    }

    return true;
}

Original comment by Giggs...@gmail.com on 23 Aug 2012 at 4:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

char *astl_WideCharToChar2(const wchar_t *pwstr)
{
    int nlength = wcslen(pwstr) * 2;
    int nbytes = WideCharToMultiByte( 0, 0, pwstr, nlength, NULL, 0, NULL, NULL);
    if(nbytes > nlength)
    { 
        nbytes = nlength;
    }
    char *pcstr = new char[nbytes + 1];
    ZeroMemory(pcstr, nbytes + 1);
    WideCharToMultiByte(0, 0, pwstr, nlength, pcstr, nbytes, NULL, NULL);
    return pcstr ;
}

wchar_t *astl_CharToWideChar2(const char *str)
{
    if(str)
    {
        wchar_t *pwstr = NULL;
        size_t nu = strlen(str) + 1;
        pwstr = new wchar_t[nu];
        size_t n = (size_t)MultiByteToWideChar(CP_ACP, 0, (const char *)str, (int)nu, NULL, 0);
        if( n >= nu)
        {
            n = nu - 1;
        }
        MultiByteToWideChar(CP_ACP, 0, (const char *)str, (int)nu, pwstr, (int)n);
        pwstr[n] = 0;
        return pwstr;
    }
    return NULL;
}

Original comment by Giggs...@gmail.com on 5 Sep 2012 at 11:33

GoogleCodeExporter commented 9 years ago

bool Controller_Connect2Server()
{
    m_sock = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(m_sock == INVALID_SOCKET)
    {
        ::OutputDebugStringA("connect failure...\r\n");
        return false;
    }
    //get local address
    char name[255]; 
    PHOSTENT hostinfo;
    ULONG ulLocalAddress = 0;
    if(gethostname(name, sizeof(name)) == 0) 
    {
        if((hostinfo = gethostbyname(name)) != NULL) 
        {
            ulLocalAddress = ((struct in_addr *)*hostinfo->h_addr_list)->S_un.S_addr; 
        }
    }
    if (ulLocalAddress == 0)
    {
        ::OutputDebugStringA("connect failure...\r\n");
        return false;
    }

    sockaddr_in servAddr; 
    servAddr.sin_family = AF_INET;
    servAddr.sin_port = htons(80);
    servAddr.sin_addr.S_un.S_addr = inet_addr("220.181.111.147");
    if(::connect(m_sock, (sockaddr*)&servAddr, sizeof(servAddr)) == -1)
    {
        ::OutputDebugStringA("connect failure...\r\n");
        return false;
    }
    ::OutputDebugStringA("connect success...\r\n");

    return true;
}

Original comment by Giggs...@gmail.com on 6 Sep 2012 at 3:27

GoogleCodeExporter commented 9 years ago
刑赏忠厚之至论維基文庫,自由的圖書館
跳转到: 导航、 搜索 
尧舜禹汤文武成康之际,何其爱民之深,忧民之切,而待天��
�之以君子长者之道也。有一善,从而赏之,又从而咏歌嗟叹�
��,所以乐其始而勉其终;有一不善,从而罚之,又从而哀矜
惩创之,所以弃其旧而开其新。故其吁俞之声, 
欢忻惨戚,见于虞夏商周之书。

成康既没,穆王立而周道始衰,然犹命其臣吕侯,而告之以��
�刑。其言忧而不伤,威而不怒,慈爱而能断,恻然有哀怜无�
��之心,故孔子犹有取焉。传曰:“赏疑从与,所以广恩也;
罚疑从去,所以谨刑也。”

当尧之时,皋陶为士,将杀人。皋陶曰:“杀之”三;尧曰��
�“宥之”三。故天下畏皋陶执法之坚,而乐尧用刑之宽。四�
��曰:“鲧可用。”尧曰:“不可。鲧方命圮族。”既而曰:
“试之。”何尧之不听皋陶之杀人,而从四岳之用鲧也?然��
�圣人之意,盖亦可见矣。书曰:“罪疑惟轻,功疑惟重。与�
��杀不辜,宁失不经。”呜呼!尽之矣。

可以赏,可以无赏,赏之过乎仁;可以罚,可以无罚,罚之��
�乎义。过乎仁,不失为君子;过乎义,则流而入于忍人。故�
��可过也,义不可过也。古者赏不以爵禄,刑不以刀锯。赏以
爵禄,是赏之道,行于爵禄之所加,而不行于爵禄之所不加��
�。刑以刀锯,是刑之威,施于刀锯之所及,而不施于刀锯之�
��不及也。先王知天下之善不胜赏,而爵禄不足以劝也;知天
下之恶不胜刑,而刀锯不足以裁也。是故疑则举而归之于仁��
�以君子长者之道待天下,使天下相率而归于君子长者之道。�
��曰:忠厚之至也。

诗曰:“君子如祉, 乱庶遄已;君子如怒,乱庶遄沮。” 
夫君子之已乱,岂有异术哉?制其喜怒,而不失乎仁而已矣��
�春秋之义,立法贵严,而责人贵宽,因其褒贬之义以制赏罚�
��亦忠厚之至也。

来自“http://zh.wikisource.org/w/index.php?title=刑賞忠厚之至論&oldid=
329999” 

Original comment by Giggs...@gmail.com on 7 Sep 2012 at 9:25

GoogleCodeExporter commented 9 years ago
damn me!
http://blog.csdn.net/jxayxym/article/details/5454530
should succeed this time!Damn!Damn me!Time is limited!

Original comment by Giggs...@gmail.com on 10 Sep 2012 at 7:13

GoogleCodeExporter commented 9 years ago
Interview:
http://blog.csdn.net/v_july_v/article/details/7974418
HBase:
http://stones333.blogspot.hk/2012/03/simple-mapreduce-program-with-hbase.html

Original comment by Giggs...@gmail.com on 11 Oct 2012 at 8:29

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 16 Oct 2012 at 8:16

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
static void Main(string[] args)
        {
            string cString = "Data Source=130.21.202.74;Initial Catalog=TestTable;User ID=TABATCH;Password=Abcd1234;";
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = cString;
            try
            {
                conn.Open();
                Console.WriteLine("opened");

                //insert data & print datetime
                //...

                //analyse & print datetime
                //...

                SqlCommand cmd = null;
                string sql = "insert into () values ()";
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();

                SqlDataReader dr = null;
                sql = "select * from ";
                dr = cmd.ExecuteReader();

                conn.Close();
                Console.WriteLine("work fine");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

Original comment by Giggs...@gmail.com on 31 Oct 2012 at 6:29

GoogleCodeExporter commented 9 years ago
DistributedCache.addFileToClassPath(new Path( 

         "/lib/mysql-connector-java-5.1.18-bin.jar"), conf); 

Original comment by Giggs...@gmail.com on 1 Nov 2012 at 10:00

GoogleCodeExporter commented 9 years ago
Requested replication 0 is less than the required minimum 1

Original comment by Giggs...@gmail.com on 2 Nov 2012 at 12:07

GoogleCodeExporter commented 9 years ago
https://github.com/sujee/hbase-mapreduce/tree/master/src/hbase_mapred1

Original comment by Giggs...@gmail.com on 2 Nov 2012 at 6:35

GoogleCodeExporter commented 9 years ago
http://www.larsgeorge.com/2009/05/hbase-mapreduce-101-part-i.html
http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/mapred/JobClient.html
http://wiki.apache.org/hadoop/Hbase/MapReduce
http://sujee.net/tech/articles/hadoop/hbase-map-reduce-freq-counter/
https://github.com/sujee/hbase-mapreduce/tree/master/src/hbase_mapred1

Original comment by Giggs...@gmail.com on 2 Nov 2012 at 7:21

GoogleCodeExporter commented 9 years ago
code sample:
log file->hbase  http://wiki.apache.org/hadoop/Hbase/MapReduce

Original comment by Giggs...@gmail.com on 6 Nov 2012 at 9:37

GoogleCodeExporter commented 9 years ago
static DWORD WINAPI RecvThreadProc(LPVOID lpParam)
{
    while (true)
    {
        int byteCount = 0;
        //select
        if ((byteCount = NW_SocketAvailable(m_sockClient, SOCKET_AVAILABLE_TYPE_READ, 20)) == SOCKET_AVAILABLE_TYPE_DROPLINE)
        {
            //check if disconnect by user.If yes....?
            //...

            PrintConsoleLog(WCLao_DEBUG, "drop line...");
            break;
        }
        if (byteCount <= 0)
        {
            continue;
        }
        CStringA s = "";
        s.Format("%d bytes can be Read", byteCount);
        PrintConsoleLog(WCLao_DEBUG, s.GetBuffer());
        //copy data from network    
        //
        int byteCountActual = 0;
        if (byteCount > m_pDataReceived->size - m_pDataReceived->offset)
        {
            //enlarge buffer
            int newSize = m_pDataReceived->offset + byteCount;
            char *buf = new char[newSize];
            memcpy(buf, m_pDataReceived->pData, m_pDataReceived->offset);
            delete m_pDataReceived->pData;
            m_pDataReceived->pData = buf;
            m_pDataReceived->size = newSize;
            PrintConsoleLog(WCLao_DEBUG, "recv buf new size...");
        }
        byteCountActual = ::recv(m_sockClient, m_pDataReceived->pData + m_pDataReceived->offset, byteCount, 0);
        m_pDataReceived->offset += byteCountActual;
        //recv a full packet and post to UI thread
        //
        //check to see if it is at least a package length.If yes,remove to UI
        do
        {
            int packageLen = 0;
            if (m_pDataReceived->offset > SIZE_CommonHeader)
            {
                packageLen = SIZE_CommonHeader + ((CommonHeader * )m_pDataReceived->pData)->dwBodyLength;
                if (packageLen != 0 && m_pDataReceived->offset >= packageLen)
                {
                    char *bufToUI = new char[packageLen];
                    memcpy(bufToUI, m_pDataReceived->pData, packageLen);
                    memcpy(m_pDataReceived->pData, m_pDataReceived->pData + packageLen, m_pDataReceived->offset - packageLen);
                    m_pDataReceived->offset = m_pDataReceived->offset - packageLen;
                    //calll back UI.bufToUI/packageLen
                    //...
                    m_pCB(((CommonHeader * )m_pDataReceived->pData)->enot, bufToUI, packageLen);
                    continue;
                }
            }
            break;
        } 
        while(true);
    }
    PrintConsoleLog(WCLao_DEBUG, "recv thread exit from while and exit...");

    return 0;
}

static void m_OnReadCompleted(SockContext *pContext, PerIOBuffer *pBuffer)
{
    PrintConsoleLogA(WCLao_INFO, "m_OnReadCompleted....");
    manager_OnReadCompleted(pContext, pBuffer);
}  

static void m_OnConnectionEstablished(SockContext *pContext, PerIOBuffer 
*pPerIOBuffer)
{
    BOOL bOptVal = TRUE;
    int iOptLen = sizeof(BOOL);
    if (setsockopt(pContext->sock, IPPROTO_TCP, TCP_NODELAY, (char *)&bOptVal, iOptLen) != 0)
    {
        ReleaseContext(pContext);
        return;
    }

    pContext->pstruct_connection = manager_AddConnection(pContext);
    m_OnReadCompleted(pContext, pPerIOBuffer);
} 

void manager_OnReadCompleted(SockContext *pContext, PerIOBuffer *pBuffer)
{
    struct_connection *psc = (struct_connection *)pContext->pstruct_connection;
    if (!psc || !psc->pContext || !pBuffer)
    {
        PrintConsoleLogA(WCLao_INFO, "app layer exit first.Then com layer");
        return;
    }
    if (psc->size == 0)
    {
        if (pBuffer->iBufferLength > STRUCT_CONNECTION_BUFFER_LENGTH_Initial)
        {
            psc->size = pBuffer->iBufferLength;
        }
        else
        {
            psc->size = STRUCT_CONNECTION_BUFFER_LENGTH_Initial;
        }
        psc->pszBuffer = new char[psc->size];
    }
    else
    {
        //enlarge the buffer
        if (pBuffer->iBufferLength > psc->size - psc->offset)
        {
            char *p = new char[psc->size + pBuffer->iBufferLength];
            memcpy(p, psc->pszBuffer, psc->offset);
            delete psc->pszBuffer;
            psc->pszBuffer = p;
        }
    }
    memcpy(psc->pszBuffer + psc->offset, pBuffer->pszBuffer, pBuffer->iBufferLength);
    psc->offset += pBuffer->iBufferLength;
    if (psc->offset >= SIZE_CommonHeader)
    {
        CommonHeader *pch = (CommonHeader *)psc->pszBuffer;
        int iPackageLen = pch->dwBodyLength + SIZE_CommonHeader;
        if (iPackageLen <= psc->offset)
        {
            Protocol_Dispatcher(psc);//handle this req
            if (psc->pContext)//may logged out
            {
                memcpy(psc->pszBuffer, psc->pszBuffer + iPackageLen, psc->offset - iPackageLen);
                psc->offset = psc->offset - iPackageLen;
            }
        }
    }
}

typedef void (*m_pfNetworkCallback)(enumNetworkOperationType t, char *pszData, 
size_t stLength);

static void NetworkEventHandler(enumNetworkOperationType t, char *pszData, 
size_t stLength)
{
    //transfer to UI or not
    //...
    //m_pCB(enumNetworkOperationType t, char *pszData, size_t stLength);

    bool bServerDisconnect = false;
    Protocol_Dispatcher(t, pszData, stLength, bServerDisconnect);
}

Original comment by Giggs...@gmail.com on 14 Dec 2012 at 11:15

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 16 Jan 2013 at 10:18

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 14 Jun 2013 at 11:00