Junior Member
|
07-11-2013
, 00:30
Re: [EXTENSION] Socket (3.0.1)
|
#407
|
Hey guy,I'm Chinese,I am sorry for my poor english, so please forgive me to talk with you with h ehelp of some tools.
I use MYSQL for while someone join sever,broadcast his IP address
Quote:
#include <sourcemod>
#include <dbi>
#pragma semicolon 1
#define CD_VERSION "1.0"
public Plugin:myinfo =
{
name = "SHAIT IP-ADDRESS",
author = "量子游戏 Dave",
description = "",
version = CD_VERSION,
url = "[IMG]file:///C:/Users/ADMINI~1/AppData/Local/Temp/[5UQ[BL(6~BS2JV6W%7DN6[%25S.png[/IMG]www.shait.net"
}
public OnClientPostAdminCheck(client)
{
if(IsFakeClient(client)) return;
decl String:gName[MAX_NAME_LENGTH+1],
String:gIp[16],
String:gAuth[21];
GetClientName(client, gName, MAX_NAME_LENGTH);
GetClientIP(client, gIp, sizeof(gIp));
GetClientAuthString(client, gAuth, sizeof(gAuth));
new Handle:kv = CreateKeyValues("sql");
KvSetString(kv, "driver", "mysql");
KvSetString(kv, "host", "[IMG]file:///C:/Users/ADMINI~1/AppData/Local/Temp/[5UQ[BL(6~BS2JV6W%7DN6[%25S.png[/IMG]www.shait.net");
KvSetString(kv, "port", "7777");
KvSetString(kv, "database", "ipdb");
KvSetString(kv, "user", "dave");
KvSetString(kv, "pass", "Dave_031");
decl String:error[255];
new Handle:hDatabase = SQL_ConnectCustom(kv, error, sizeof(error), true);
CloseHandle(kv);
if (hDatabase == INVALID_HANDLE)
{
LogError("SQL Connection Failed: %s", error);
return;
}
decl String:query[150];
Format(query, 150, "SELECT address FROM ip WHERE ip1<= INET_ATON('%s') AND ip2>= INET_ATON('%s')", gIp, gIp);
SQL_FastQuery(hDatabase, "SET NAMES \"UTF8\"");
new Handle:queryH = SQL_Query(hDatabase, query);
if(!queryH){
PrintToChatAll("\x01欢迎 \x04来自火星\x01的朋友\x04%s\x01进入量子服务器", gName );
return;
}
decl String:qAddress[150];
SQL_FetchString(queryH, 0, qAddress, sizeof(qAddress));
if(queryH != INVALID_HANDLE){
PrintToChatAll("\x01欢迎来自\x04%s\x01的玩家\x04%s\x 01进入量子服务器", qAddress, gName );
}
else{
LogError("SQL SELECT Failed: %s", error);
}
CloseHandle(queryH);
}
|
But when many people in the sever,it's mega lag.
So i want to ask a questions,how to send Socket in URL and receive that.
I try to do it,but it's not work.
Quote:
#include <sourcemod>
#include <socket>
#define CD_VERSION "1.0"
public Plugin:myinfo =
{
name = "SHAIT IP-ADDRESS",
author = "量子游戏, Dave",
description = "",
version = CD_VERSION,
url = "www.shait.net"
}
public OnSocketError(Handle:socket, const errorType, const errorNum, any:arg)
{
LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(socket);
}
public OnSocketConnected(Handle:socket, any:arg)
{
SocketSend(socket, "USER MyUserName\r\n");
}
public OnClientPostAdminCheck(client)
{
if(IsFakeClient(client)) return;
decl String:gName[MAX_NAME_LENGTH+1],
String:gIp[16],
String:gAuth[21];
GetClientName(client, gName, MAX_NAME_LENGTH);
GetClientIP(client, gIp, sizeof(gIp));
GetClientAuthString(client, gAuth, sizeof(gAuth));
new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);
decl String:qUrl[250];
Format(gUrl, 250, "http://www.youdao.com/smartresult-xm...k&type=ip&q=%s", gIp);
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, gUrl, 80);
}
public OnSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:arg)
{
if (!StrContains(receiveData, "location"))
{
PrintToChatAll("显示来自%s的玩家%s", receiveDate, gName );
}
else
{
PrintToChatAll("显示来自火星的玩家%s", gName );
}
}
public OnSocketConnected(Handle:socket, any:arg)
{
SocketSend(socket, gIp);
}
|
thank you very much
|
|