Skip to content

Commit 6cf98f5

Browse files
committed
First Commit
0 parents  commit 6cf98f5

22 files changed

+1386
-0
lines changed

.gitignore

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.userosscache
8+
*.sln.docstates
9+
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
13+
# Build results
14+
[Dd]ebug/
15+
[Dd]ebugPublic/
16+
[Rr]elease/
17+
[Rr]eleases/
18+
x64/
19+
x86/
20+
build/
21+
bld/
22+
[Bb]in/
23+
[Oo]bj/
24+
25+
# Visual Studo 2015 cache/options directory
26+
.vs/
27+
28+
# MSTest test Results
29+
[Tt]est[Rr]esult*/
30+
[Bb]uild[Ll]og.*
31+
32+
# NUNIT
33+
*.VisualState.xml
34+
TestResult.xml
35+
36+
# Build Results of an ATL Project
37+
[Dd]ebugPS/
38+
[Rr]eleasePS/
39+
dlldata.c
40+
41+
*_i.c
42+
*_p.c
43+
*_i.h
44+
*.ilk
45+
*.meta
46+
*.obj
47+
*.pch
48+
*.pdb
49+
*.pgc
50+
*.pgd
51+
*.rsp
52+
*.sbr
53+
*.tlb
54+
*.tli
55+
*.tlh
56+
*.tmp
57+
*.tmp_proj
58+
*.log
59+
*.vspscc
60+
*.vssscc
61+
.builds
62+
*.pidb
63+
*.svclog
64+
*.scc
65+
66+
# Chutzpah Test files
67+
_Chutzpah*
68+
69+
# Visual C++ cache files
70+
ipch/
71+
*.aps
72+
*.ncb
73+
*.opensdf
74+
*.sdf
75+
*.cachefile
76+
77+
# Visual Studio profiler
78+
*.psess
79+
*.vsp
80+
*.vspx
81+
82+
# TFS 2012 Local Workspace
83+
$tf/
84+
85+
# Guidance Automation Toolkit
86+
*.gpState
87+
88+
# ReSharper is a .NET coding add-in
89+
_ReSharper*/
90+
*.[Rr]e[Ss]harper
91+
*.DotSettings.user
92+
93+
# JustCode is a .NET coding addin-in
94+
.JustCode
95+
96+
# TeamCity is a build add-in
97+
_TeamCity*
98+
99+
# DotCover is a Code Coverage Tool
100+
*.dotCover
101+
102+
# NCrunch
103+
_NCrunch_*
104+
.*crunch*.local.xml
105+
106+
# MightyMoose
107+
*.mm.*
108+
AutoTest.Net/
109+
110+
# Web workbench (sass)
111+
.sass-cache/
112+
113+
# Installshield output folder
114+
[Ee]xpress/
115+
116+
# DocProject is a documentation generator add-in
117+
DocProject/buildhelp/
118+
DocProject/Help/*.HxT
119+
DocProject/Help/*.HxC
120+
DocProject/Help/*.hhc
121+
DocProject/Help/*.hhk
122+
DocProject/Help/*.hhp
123+
DocProject/Help/Html2
124+
DocProject/Help/html
125+
126+
# Click-Once directory
127+
publish/
128+
129+
# Publish Web Output
130+
*.[Pp]ublish.xml
131+
*.azurePubxml
132+
# TODO: Comment the next line if you want to checkin your web deploy settings
133+
# but database connection strings (with potential passwords) will be unencrypted
134+
*.pubxml
135+
*.publishproj
136+
137+
# NuGet Packages
138+
*.nupkg
139+
# The packages folder can be ignored because of Package Restore
140+
**/packages/*
141+
# except build/, which is used as an MSBuild target.
142+
!**/packages/build/
143+
# Uncomment if necessary however generally it will be regenerated when needed
144+
#!**/packages/repositories.config
145+
146+
# Windows Azure Build Output
147+
csx/
148+
*.build.csdef
149+
150+
# Windows Store app package directory
151+
AppPackages/
152+
153+
# Others
154+
*.[Cc]ache
155+
ClientBin/
156+
[Ss]tyle[Cc]op.*
157+
~$*
158+
*~
159+
*.dbmdl
160+
*.dbproj.schemaview
161+
*.pfx
162+
*.publishsettings
163+
node_modules/
164+
bower_components/
165+
166+
# RIA/Silverlight projects
167+
Generated_Code/
168+
169+
# Backup & report files from converting an old project file
170+
# to a newer Visual Studio version. Backup files are not needed,
171+
# because we have git ;-)
172+
_UpgradeReport_Files/
173+
Backup*/
174+
UpgradeLog*.XML
175+
UpgradeLog*.htm
176+
177+
# SQL Server files
178+
*.mdf
179+
*.ldf
180+
181+
# Business Intelligence projects
182+
*.rdl.data
183+
*.bim.layout
184+
*.bim_*.settings
185+
186+
# Microsoft Fakes
187+
FakesAssemblies/
188+
189+
# Node.js Tools for Visual Studio
190+
.ntvs_analysis.dat
191+
192+
# Visual Studio 6 build log
193+
*.plg
194+
195+
# Visual Studio 6 workspace options file
196+
*.opt

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# CQSocketAPI
2+
CoolQ Socket API written in VC++.
3+
4+
## Protocol
5+
6+
### Communication
7+
Server and client communicate by send UDP frame to each others. Fields are joined by one space in a frame.
8+
9+
The server port is 11231 and client is 11232.
10+
11+
### Frame
12+
```
13+
Frame = Prefix (max 256) + Payload (max 32768)
14+
Prefix = 'PrivateMessage' | 'GroupMessage' | 'DiscussMessage'
15+
16+
Received Message Payload:
17+
PrivateMessage = QQ + encoded_text
18+
GroupMessage = GroupID + QQ + encoded_text
19+
GroupMessage = DiscussID + QQ + encoded_text
20+
21+
Send Message Payload:
22+
PrivateMessage = QQ + encoded_text
23+
GroupMessage = GroupID + encoded_text
24+
GroupMessage = DiscussID + encoded_text
25+
26+
encoded_text = base64_encode( GBK_encode( text ) )
27+
```

cqsocketapi.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "org.dazzyd.cqsocketapi", "cqsocketapi\cqsocketapi.vcxproj", "{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}"
5+
EndProject
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "udpserver", "udpserver\udpserver.vcxproj", "{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Win32 = Debug|Win32
11+
Release|Win32 = Release|Win32
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Debug|Win32.ActiveCfg = Release|Win32
15+
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Debug|Win32.Build.0 = Release|Win32
16+
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Release|Win32.ActiveCfg = Release|Win32
17+
{9D36EAFF-6BF0-4BDE-A20C-5BCB92DE79D6}.Release|Win32.Build.0 = Release|Win32
18+
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Debug|Win32.ActiveCfg = Debug|Win32
19+
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Debug|Win32.Build.0 = Debug|Win32
20+
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Release|Win32.ActiveCfg = Release|Win32
21+
{83EB88B4-0DD8-4E76-8A2E-5AE97BBFB6DB}.Release|Win32.Build.0 = Release|Win32
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
EndGlobal

cqsocketapi/APIClient.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "stdafx.h"
2+
3+
#include "APIClient.h"
4+
#include "appmain.h"
5+
6+
7+
APIClient::APIClient(void)
8+
{
9+
WSADATA wsa;
10+
WSAStartup(MAKEWORD(1, 1), &wsa);
11+
12+
sock = socket(AF_INET, SOCK_DGRAM, 0);
13+
remoteInfo.sin_family = AF_INET;
14+
remoteInfo.sin_addr.s_addr = inet_addr("127.0.0.1");
15+
remoteInfo.sin_port = htons(API_CLIENT_PORT);
16+
}
17+
18+
19+
APIClient::~APIClient(void)
20+
{
21+
closesocket(sock);
22+
}
23+
24+
25+
void APIClient::send(const char *buffer, const int len)
26+
{
27+
sendto(sock, buffer, len, 0, (sockaddr *)&remoteInfo, sizeof(remoteInfo));
28+
}

cqsocketapi/APIClient.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "winsock2.h"
4+
5+
class APIClient
6+
{
7+
public:
8+
APIClient(void);
9+
~APIClient(void);
10+
void send(const char *buffer, const int len);
11+
private:
12+
SOCKET sock;
13+
struct sockaddr_in remoteInfo;
14+
};

cqsocketapi/APIServer.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "stdafx.h"
2+
#include "string.h"
3+
#include "cqp.h"
4+
5+
#include "APIServer.h"
6+
#include "appmain.h"
7+
#include "base64.h"
8+
9+
extern int appAuthCode;
10+
11+
12+
/********
13+
* Message Processer
14+
********/
15+
void prcsPrivateMessage(const char *payload) {
16+
int64_t qq;
17+
char text[FRAME_PAYLOAD_SIZE];
18+
sscanf_s(payload, "%d %[^\n]", &qq, text, sizeof(text));
19+
20+
char decodedText[FRAME_PAYLOAD_SIZE];
21+
Base64decode(decodedText, text);
22+
23+
CQ_sendPrivateMsg(appAuthCode, qq, decodedText);
24+
}
25+
26+
void prcsGroupMessage(const char *payload) {
27+
int64_t group;
28+
char text[FRAME_PAYLOAD_SIZE];
29+
sscanf_s(payload, "%d %[^\n]", &group, text, sizeof(text));
30+
31+
char decodedText[FRAME_PAYLOAD_SIZE];
32+
Base64decode(decodedText, text);
33+
34+
CQ_sendGroupMsg(appAuthCode, group, decodedText);
35+
}
36+
37+
38+
/********
39+
* API Server
40+
********/
41+
APIServer::APIServer(void)
42+
{
43+
WSADATA wsa;
44+
WSAStartup(MAKEWORD(1, 1), &wsa);
45+
46+
localInfo.sin_family = AF_INET;
47+
localInfo.sin_addr.s_addr = INADDR_ANY; // inet_addr("127.0.0.1")
48+
localInfo.sin_port = htons(API_SERVER_PORT);
49+
50+
sock = socket(AF_INET, SOCK_DGRAM, 0);
51+
bind(sock, (sockaddr *)&localInfo, sizeof(localInfo));
52+
}
53+
54+
55+
APIServer::~APIServer(void)
56+
{
57+
closesocket(sock);
58+
}
59+
60+
61+
void APIServer::run()
62+
{
63+
char buffer[FRAME_SIZE];
64+
char prefix[FRAME_PREFIX_SIZE];
65+
char payload[FRAME_PAYLOAD_SIZE];
66+
67+
while (1) {
68+
memset(buffer, 0, sizeof(buffer));
69+
memset(prefix, 0, sizeof(prefix));
70+
memset(payload, 0, sizeof(payload));
71+
if (recv(sock, buffer, sizeof(buffer), 0) != SOCKET_ERROR) {
72+
sscanf_s(buffer, "%s %[^\n]", prefix, sizeof(prefix), payload, sizeof(payload));
73+
74+
if (strcmp(prefix, "PrivateMessage") == 0) {
75+
prcsPrivateMessage(payload);
76+
}
77+
if (strcmp(prefix, "GroupMessage") == 0) {
78+
prcsGroupMessage(payload);
79+
}
80+
}
81+
}
82+
}

cqsocketapi/APIServer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include "winsock2.h"
4+
5+
class APIServer
6+
{
7+
public:
8+
APIServer(void);
9+
~APIServer(void);
10+
void run();
11+
private:
12+
SOCKET sock;
13+
struct sockaddr_in localInfo;
14+
};
15+

cqsocketapi/CQP.lib

8.52 KB
Binary file not shown.

0 commit comments

Comments
 (0)