-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6cf98f5
Showing
22 changed files
with
1,386 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# User-specific files (MonoDevelop/Xamarin Studio) | ||
*.userprefs | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
x64/ | ||
x86/ | ||
build/ | ||
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
# Visual Studo 2015 cache/options directory | ||
.vs/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
# NUNIT | ||
*.VisualState.xml | ||
TestResult.xml | ||
|
||
# Build Results of an ATL Project | ||
[Dd]ebugPS/ | ||
[Rr]eleasePS/ | ||
dlldata.c | ||
|
||
*_i.c | ||
*_p.c | ||
*_i.h | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.svclog | ||
*.scc | ||
|
||
# Chutzpah Test files | ||
_Chutzpah* | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
*.cachefile | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
|
||
# TFS 2012 Local Workspace | ||
$tf/ | ||
|
||
# Guidance Automation Toolkit | ||
*.gpState | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper*/ | ||
*.[Rr]e[Ss]harper | ||
*.DotSettings.user | ||
|
||
# JustCode is a .NET coding addin-in | ||
.JustCode | ||
|
||
# TeamCity is a build add-in | ||
_TeamCity* | ||
|
||
# DotCover is a Code Coverage Tool | ||
*.dotCover | ||
|
||
# NCrunch | ||
_NCrunch_* | ||
.*crunch*.local.xml | ||
|
||
# MightyMoose | ||
*.mm.* | ||
AutoTest.Net/ | ||
|
||
# Web workbench (sass) | ||
.sass-cache/ | ||
|
||
# Installshield output folder | ||
[Ee]xpress/ | ||
|
||
# DocProject is a documentation generator add-in | ||
DocProject/buildhelp/ | ||
DocProject/Help/*.HxT | ||
DocProject/Help/*.HxC | ||
DocProject/Help/*.hhc | ||
DocProject/Help/*.hhk | ||
DocProject/Help/*.hhp | ||
DocProject/Help/Html2 | ||
DocProject/Help/html | ||
|
||
# Click-Once directory | ||
publish/ | ||
|
||
# Publish Web Output | ||
*.[Pp]ublish.xml | ||
*.azurePubxml | ||
# TODO: Comment the next line if you want to checkin your web deploy settings | ||
# but database connection strings (with potential passwords) will be unencrypted | ||
*.pubxml | ||
*.publishproj | ||
|
||
# NuGet Packages | ||
*.nupkg | ||
# The packages folder can be ignored because of Package Restore | ||
**/packages/* | ||
# except build/, which is used as an MSBuild target. | ||
!**/packages/build/ | ||
# Uncomment if necessary however generally it will be regenerated when needed | ||
#!**/packages/repositories.config | ||
|
||
# Windows Azure Build Output | ||
csx/ | ||
*.build.csdef | ||
|
||
# Windows Store app package directory | ||
AppPackages/ | ||
|
||
# Others | ||
*.[Cc]ache | ||
ClientBin/ | ||
[Ss]tyle[Cc]op.* | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.dbproj.schemaview | ||
*.pfx | ||
*.publishsettings | ||
node_modules/ | ||
bower_components/ | ||
|
||
# RIA/Silverlight projects | ||
Generated_Code/ | ||
|
||
# Backup & report files from converting an old project file | ||
# to a newer Visual Studio version. Backup files are not needed, | ||
# because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
UpgradeLog*.htm | ||
|
||
# SQL Server files | ||
*.mdf | ||
*.ldf | ||
|
||
# Business Intelligence projects | ||
*.rdl.data | ||
*.bim.layout | ||
*.bim_*.settings | ||
|
||
# Microsoft Fakes | ||
FakesAssemblies/ | ||
|
||
# Node.js Tools for Visual Studio | ||
.ntvs_analysis.dat | ||
|
||
# Visual Studio 6 build log | ||
*.plg | ||
|
||
# Visual Studio 6 workspace options file | ||
*.opt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# CQSocketAPI | ||
CoolQ Socket API written in VC++. | ||
|
||
## Protocol | ||
|
||
### Communication | ||
Server and client communicate by send UDP frame to each others. Fields are joined by one space in a frame. | ||
|
||
The server port is 11231 and client is 11232. | ||
|
||
### Frame | ||
``` | ||
Frame = Prefix (max 256) + Payload (max 32768) | ||
Prefix = 'PrivateMessage' | 'GroupMessage' | 'DiscussMessage' | ||
Received Message Payload: | ||
PrivateMessage = QQ + encoded_text | ||
GroupMessage = GroupID + QQ + encoded_text | ||
GroupMessage = DiscussID + QQ + encoded_text | ||
Send Message Payload: | ||
PrivateMessage = QQ + encoded_text | ||
GroupMessage = GroupID + encoded_text | ||
GroupMessage = DiscussID + encoded_text | ||
encoded_text = base64_encode( GBK_encode( text ) ) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "org.dazzyd.cqsocketapi", "cqsocketapi\cqsocketapi.vcxproj", "{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}" | ||
EndProject | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "udpserver", "udpserver\udpserver.vcxproj", "{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Win32 = Debug|Win32 | ||
Release|Win32 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Debug|Win32.ActiveCfg = Release|Win32 | ||
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Debug|Win32.Build.0 = Release|Win32 | ||
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Release|Win32.ActiveCfg = Release|Win32 | ||
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Release|Win32.Build.0 = Release|Win32 | ||
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Debug|Win32.Build.0 = Debug|Win32 | ||
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Release|Win32.ActiveCfg = Release|Win32 | ||
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Release|Win32.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "stdafx.h" | ||
|
||
#include "APIClient.h" | ||
#include "appmain.h" | ||
|
||
|
||
APIClient::APIClient(void) | ||
{ | ||
WSADATA wsa; | ||
WSAStartup(MAKEWORD(1, 1), &wsa); | ||
|
||
sock = socket(AF_INET, SOCK_DGRAM, 0); | ||
remoteInfo.sin_family = AF_INET; | ||
remoteInfo.sin_addr.s_addr = inet_addr("127.0.0.1"); | ||
remoteInfo.sin_port = htons(API_CLIENT_PORT); | ||
} | ||
|
||
|
||
APIClient::~APIClient(void) | ||
{ | ||
closesocket(sock); | ||
} | ||
|
||
|
||
void APIClient::send(const char *buffer, const int len) | ||
{ | ||
sendto(sock, buffer, len, 0, (sockaddr *)&remoteInfo, sizeof(remoteInfo)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include "winsock2.h" | ||
|
||
class APIClient | ||
{ | ||
public: | ||
APIClient(void); | ||
~APIClient(void); | ||
void send(const char *buffer, const int len); | ||
private: | ||
SOCKET sock; | ||
struct sockaddr_in remoteInfo; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "stdafx.h" | ||
#include "string.h" | ||
#include "cqp.h" | ||
|
||
#include "APIServer.h" | ||
#include "appmain.h" | ||
#include "base64.h" | ||
|
||
extern int appAuthCode; | ||
|
||
|
||
/******** | ||
* Message Processer | ||
********/ | ||
void prcsPrivateMessage(const char *payload) { | ||
int64_t qq; | ||
char text[FRAME_PAYLOAD_SIZE]; | ||
sscanf_s(payload, "%d %[^\n]", &qq, text, sizeof(text)); | ||
|
||
char decodedText[FRAME_PAYLOAD_SIZE]; | ||
Base64decode(decodedText, text); | ||
|
||
CQ_sendPrivateMsg(appAuthCode, qq, decodedText); | ||
} | ||
|
||
void prcsGroupMessage(const char *payload) { | ||
int64_t group; | ||
char text[FRAME_PAYLOAD_SIZE]; | ||
sscanf_s(payload, "%d %[^\n]", &group, text, sizeof(text)); | ||
|
||
char decodedText[FRAME_PAYLOAD_SIZE]; | ||
Base64decode(decodedText, text); | ||
|
||
CQ_sendGroupMsg(appAuthCode, group, decodedText); | ||
} | ||
|
||
|
||
/******** | ||
* API Server | ||
********/ | ||
APIServer::APIServer(void) | ||
{ | ||
WSADATA wsa; | ||
WSAStartup(MAKEWORD(1, 1), &wsa); | ||
|
||
localInfo.sin_family = AF_INET; | ||
localInfo.sin_addr.s_addr = INADDR_ANY; // inet_addr("127.0.0.1") | ||
localInfo.sin_port = htons(API_SERVER_PORT); | ||
|
||
sock = socket(AF_INET, SOCK_DGRAM, 0); | ||
bind(sock, (sockaddr *)&localInfo, sizeof(localInfo)); | ||
} | ||
|
||
|
||
APIServer::~APIServer(void) | ||
{ | ||
closesocket(sock); | ||
} | ||
|
||
|
||
void APIServer::run() | ||
{ | ||
char buffer[FRAME_SIZE]; | ||
char prefix[FRAME_PREFIX_SIZE]; | ||
char payload[FRAME_PAYLOAD_SIZE]; | ||
|
||
while (1) { | ||
memset(buffer, 0, sizeof(buffer)); | ||
memset(prefix, 0, sizeof(prefix)); | ||
memset(payload, 0, sizeof(payload)); | ||
if (recv(sock, buffer, sizeof(buffer), 0) != SOCKET_ERROR) { | ||
sscanf_s(buffer, "%s %[^\n]", prefix, sizeof(prefix), payload, sizeof(payload)); | ||
|
||
if (strcmp(prefix, "PrivateMessage") == 0) { | ||
prcsPrivateMessage(payload); | ||
} | ||
if (strcmp(prefix, "GroupMessage") == 0) { | ||
prcsGroupMessage(payload); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "winsock2.h" | ||
|
||
class APIServer | ||
{ | ||
public: | ||
APIServer(void); | ||
~APIServer(void); | ||
void run(); | ||
private: | ||
SOCKET sock; | ||
struct sockaddr_in localInfo; | ||
}; | ||
|
Binary file not shown.
Oops, something went wrong.