OSDN Git Service

生主コメント実装
authorqwerty2501 <riot313@gmail.com>
Mon, 13 Feb 2012 13:45:49 +0000 (22:45 +0900)
committerqwerty2501 <riot313@gmail.com>
Mon, 13 Feb 2012 13:45:49 +0000 (22:45 +0900)
nlib/nlib_nicoLive.cpp
nlite.suo
nlite/nlite_commentWrite.cpp
nlite/nlite_commentWrite.h
nlite/nlite_nlib.cpp
nlite/nlite_nlib.h

index e55bad3..e3806a0 100644 (file)
@@ -1134,16 +1134,85 @@ errorend:
 
 NLIB_RESULT NicoLiveStream_sendOwnerChat(NicoLiveStream_P self,LPCTSTR chatbuf,LPCTSTR *mail,LPCTSTR *extends){
 
+       static const LPCTSTR OWNERCHAT_REQUEST = TEXT("api/broadcast/%s?body=%s%s&token=%s%s");
        NLIB_RESULT rslt = NLIB_ERR_CODE_NOTSET;
        LPVOID buffer = malloc(LENGTH_65536 * sizeof(TCHAR));
        LPTSTR requestBuffer = (LPTSTR)buffer;
        const UINT_PTR buflen = LENGTH_8192;
-       LPSTR recvBuffer = (LPSTR)&requestBuffer[buflen];
+       LPTSTR mailBuf = (LPTSTR)&requestBuffer[buflen];
+       LPTSTR extendsBuf = (LPTSTR)&mailBuf[buflen];
+       LPSTR recvBuffer = (LPSTR)&extendsBuf[buflen];
        
        DWORD readSize;
        DWORD statusCode;
        DWORD statusCodeSize = sizeof(statusCode);
-       HINTERNET hRequest = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",requestBuffer,L"1.1",(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+       UINT_PTR reqLength = _tcslen(chatbuf);
+       HINTERNET hRequest = NULL;
+       for(LPCTSTR *mailStart = mail;mailStart[0] != NULL;++mailStart){
+
+               reqLength += _tcslen(mailStart[0]);
+
+       }
+
+       LPCTSTR *extendsArrayIndex = extends;
+       for(;extendsArrayIndex[0] != NULL;extendsArrayIndex+=2){
+
+               reqLength += _tcslen(extendsArrayIndex[0]);
+               reqLength += _tcslen(extendsArrayIndex[1]);
+       }
+
+       if(reqLength > buflen / 2){
+
+               goto buffererr;
+
+       }
+       LPTSTR mailIndexPtr = mailBuf;
+       if(mail[0] == NULL){
+               _tcscpy(mailIndexPtr,TEXT(""));
+
+       } else {
+
+               _tcscpy(mailIndexPtr,TEXT("&mail="));
+               mailIndexPtr += _tcslen(mailIndexPtr);
+
+       }
+       for(LPCTSTR *mailArrayIndex = mail;mailArrayIndex[0] != NULL;++mailArrayIndex){
+
+               _tcscpy(mailIndexPtr,mailArrayIndex[0]);
+               mailIndexPtr += _tcslen(mailIndexPtr);
+
+               if(mailArrayIndex[1] != NULL){
+
+                       mailIndexPtr[0] = TEXT(' ');
+                       ++mailIndexPtr;
+
+               }
+
+       }
+
+       LPTSTR extendsIndexPtr = extendsBuf;
+       _tcscpy(extendsIndexPtr,TEXT(""));
+       for(LPCTSTR *extendsArrayIndex2 = extends;extendsArrayIndex2[0] != NULL;extendsArrayIndex2+=2){
+
+               
+               extendsIndexPtr[0] = TEXT('&');
+               ++extendsIndexPtr;
+
+               
+               _tcscpy(extendsIndexPtr,extendsArrayIndex2[0]);
+               extendsIndexPtr += _tcslen(extendsIndexPtr);
+               extendsIndexPtr[0] = TEXT('=');
+               ++extendsIndexPtr;
+               _tcscpy(extendsIndexPtr,extendsArrayIndex2[1]);
+               extendsIndexPtr += _tcslen(extendsIndexPtr);
+
+               
+       }
+
+       _stprintf(requestBuffer,OWNERCHAT_REQUEST,self->playerStatus.stream.id,chatbuf,mailBuf,self->publishStatus.token,extendsBuf);
+
+       ::EnterCriticalSection(&self->sessionManager.cs);
+       hRequest = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",requestBuffer,L"1.1",(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
 
        if(WinHttpSendRequest(hRequest,self->userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
 
@@ -1181,7 +1250,7 @@ NLIB_RESULT NicoLiveStream_sendOwnerChat(NicoLiveStream_P self,LPCTSTR chatbuf,L
 end:
        free(buffer);
        WinHttpCloseHandle(hRequest);
-
+       ::LeaveCriticalSection(&self->sessionManager.cs);
        return rslt;
 
 
@@ -1189,6 +1258,12 @@ connecterr:
 
        rslt = NLIB_FAILED_CONNECT;
        goto end;
+
+
+buffererr:
+
+       rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+       goto end;
 }
 
 
index a63d030..d9427fa 100644 (file)
Binary files a/nlite.suo and b/nlite.suo differ
index 50da8f8..a13c4c7 100644 (file)
@@ -275,11 +275,17 @@ VOID CCommentWriteWindow::OnPaint(HDC hdc){
        return;
 }
 
-static VOID EnterChatBox(LPVOID userData){
+VOID CSubChatEdit::EnterChatBox(LPVOID userData){
 
        
        ((CSubChatEdit*)userData)->SetReadOnly(TRUE);
-       Sleep(3000);
+       if(((CSubChatEdit*)userData)->self.nicoLiveStream.IsOwner()){
+
+               Sleep(1500);
+
+       }else {
+               Sleep(3000);
+       }
        ((CSubChatEdit*)userData)->AgreeEnter();
 
        _endthread();
@@ -288,7 +294,7 @@ static VOID EnterChatBox(LPVOID userData){
 
 BOOL CCommentWriteWindow::SendChat(){
 
-       _beginthread(EnterChatBox,0,&this->commentSubEdit);
+       _beginthread(CSubChatEdit::EnterChatBox,0,&this->commentSubEdit);
        
        CCommentMaker commentMaker;
        std::vector<TCHAR> chat(commentSubEdit.GetWindowTextLengthW() + 1);
@@ -329,7 +335,17 @@ BOOL CCommentWriteWindow::SendChat(){
 
 
        BOOL rslt = FALSE;
-       NLIB_RESULT code = nicoLiveStream.SendChat(commentMaker);
+       NLIB_RESULT code = NLIB_ERR_CODE_NOTSET;
+
+       if(nicoLiveStream.IsOwner() ==TRUE && this->ownerModeButton.GetCheck() == BST_CHECKED){
+               
+               code = nicoLiveStream.SendOwnerChat(commentMaker);
+
+       } else {
+
+               code = nicoLiveStream.SendChat(commentMaker);
+
+       }
 
        switch(code){
 
@@ -340,11 +356,15 @@ BOOL CCommentWriteWindow::SendChat(){
                goto end;
 
        case NLIB_ERR_NOT_LIVECONNECT:
-               
+       case NLIB_FAILED_CONNECT:       
                ::MessageBox(*this,NLIB_GetErrorMessage(code),TEXT("\83R\83\81\83\93\83g\8f\91\82«\8d\9e\82Ý\83G\83\89\81["),MB_ICONERROR | MB_OK);
                commentSubEdit.AgreeEnter();
                break;
 
+       
+
+
+
        default:
                UnexpectedErrorMessageShow(TEXT("\83R\83\81\83\93\83g\8f\91\82«\8d\9e\82Ý\92\86\82É"),NLIB_GetErrorMessage(code),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
                commentSubEdit.AgreeEnter();
index 6d722c4..2bb518a 100644 (file)
@@ -81,7 +81,7 @@ namespace nlite{
 
                        VOID AgreeEnter();
 
-
+                       static VOID EnterChatBox(LPVOID userData);
        };
 
 
index e295e1d..9ac2337 100644 (file)
@@ -183,6 +183,12 @@ NLIB_RESULT CNicoLiveStream::SendChat(CCommentMaker &commentMaker){
 
 }
 
+NLIB_RESULT CNicoLiveStream::SendOwnerChat(CCommentMaker &commentMaker){
+       commentMaker.mails.push_back(NULL);
+       commentMaker.exAttribute.push_back(NULL);
+       return NicoLiveStream_sendOwnerChat(self,commentMaker.chatString,&commentMaker.mails[0],&commentMaker.exAttribute[0]);
+}
+
 
        ///
        ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82ÌID\82ð\8eæ\93¾
index b1600ca..795dcbc 100644 (file)
@@ -170,6 +170,12 @@ namespace nlite{
                ///
                NLIB_RESULT SendChat(CCommentMaker &commentMaker);
 
+
+               ///
+               ///\90\8eå\83`\83\83\83b\83g\91\97\90M
+               ///
+               NLIB_RESULT SendOwnerChat(CCommentMaker &commentMaker);
+
                ///
                ///\83n\81[\83g\83r\81[\83g\91\97\90M
                ///