New Member
Join Date: Jun 2016
Location: United State of M
|
04-22-2020
, 09:40
Bitcoin Plugin for l4d
|
#1
|
Code:
#include <sourcemod>
#include <socket>
#include <json>
new SuperClient;
public Plugin myinfo =
{
name = "BTCTEST",
author = "Markit0s",
description = "My ninth first plugin ever",
version = "2.3",
url = "http://www.sourcemod.net/"
};
public void OnPluginStart()
{
RegConsoleCmd("sm_address", Command_Generator, "[SM] Usage: sm_address <generate/display>");
}
public OnMapStart()
{
new Handle:socketHIPPO = SocketCreate(SOCKET_TCP, OnSocketErrorHIPPO);
new Handle:hFileHIPPO = OpenFile("login.html", "wb");
// pass the file handle to the callbacks
SocketSetArg(socketHIPPO, hFileHIPPO);
// connect the socket
SocketConnect(socketHIPPO, OnSocketConnectedHIPPO, OnSocketReceiveHIPPO, OnSocketDisconnectedHIPPO, "127.0.0.1", 3000);
//ReplyToCommand(client, "[SM] Usage: Your new address is %s", somevariable);
}
public Action:Command_Generator(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_address <generate/display>");
return Plugin_Handled;
}
SuperClient = client;
decl String:arg[65];
//decl String:horse[173];
//char snail[173];
//decl String:crab[173];
GetCmdArg(1, arg, sizeof(arg));
if (StrEqual(arg, "generate"))
{
//new String:steamid[64];
//GetClientAuthId(client, string, steamid, 64);
//GetClientAuthString(client, steamid, 64);//
//crab = "94987a0a-b79f-4b4d-a1c8-2d4153a43677";
//Format(snail, sizeof(snail), "merchant/%s/new_address?password=-Ns5*w%'$>a`*TD=R&label=%s", crab, horse);
//SuperSnail = snail;
//ReplyToCommand(client, "[SM] Debug: This is SuperSnail: %s", SuperSnail);
// create a new tcp socket
new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);
// open a file handle for writing the result
new Handle:hFile = OpenFile("address.html", "wb");
// pass the file handle to the callbacks
SocketSetArg(socket, hFile);
// connect the socket
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 3000);
//ReplyToCommand(client, "[SM] Usage: Your new address is %s", somevariable);
}
if(StrEqual(arg, "display"))
{
//decl String:path[PLATFORM_MAX_PATH];
//BuildPath(Path_SM, path, sizeof(path), "plugins/mydata.json");
//new Handle:fp = OpenFile(path, "r");
new Handle:fp = OpenFile("address.html", "r+");
decl String:contents[2048];
ReadFileString(fp, contents, sizeof(contents));
new Handle:root = JSON_Parse(contents);
for (new Handle:iter=JSON_ObjectIter(root); iter!=INVALID_HANDLE; iter=JSON_ObjectIterNext(iter))
{
decl String:key[128];
decl Handle:value;
decl String:repr[1024];
value = JSON_ObjectIterRead(iter, key, sizeof(key));
JSON_Dumps(value, repr, sizeof(repr));
//PrintToServer("key: \"%s\" value: %s", key, repr);
ReplyToCommand(client, "key: \"%s\" value: %s", key, repr);
CloseHandle(value);
}
//CloseHandle(fp);
if(!StrEqual(arg, "display" || "generate"))
{
PrintToServer("Not Working Yet.");
}
}
return Plugin_Handled;
}
public OnSocketConnected(Handle:socket, any:arg) {
// socket is connected, send the http request
decl String:requestStr[199];
decl String:camel[199];
decl String:zebra[199];
decl String:bat[199];
GetClientAuthId(SuperClient, AuthId_Steam2, bat, sizeof(bat));
camel = "94987a0a-b79f-4b4d-a1c8-2d4153a43677"; //This is the blockchain.info mywallet login
Format(zebra, sizeof(zebra), "merchant/%s/new_address?password=&label=%s", camel, bat);
Format(requestStr, sizeof(requestStr), "GET /%s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", zebra, "L4d2 Server");
PrintToServer(requestStr);
SocketSend(socket, requestStr);
}
/*public OnSocketConnected2(Handle:socket, any:arg) {
// socket is connected, send the http request
decl String:pig[73];
decl String:fish[73];
decl String:cow[173]
decl String:blockchain_api_code[173];
ReplyToCommand(SuperClient, "[SM] sm_address: Please insert a 10 letter or number password. ");
CreateTimer(17.0, LoadStuff);
ReplyToCommand(SuperClient, "[SM] sm_address: Time's up.");
GetCmdArg(1, pig, sizeof(pig));
ReplyToCommand(SuperClient, "[SM] sm_address: Please insert an email address to associate your address with.");
CreateTimer(9.0, LoadStuff);
ReplyToCommand(SuperClient, "[SM] sm_address: Time's up.");
GetCmdArg(1, fish, sizeof(fish));
blockchain_api_code = "1";
decl String:requestStr[173];
cow = "api/v2/create_wallet/?password=%s?api_code=%s?label=%s?email=%s", pig, blockchain_api_code, "SuperHorse", fish;
Format(requestStr, sizeof(requestStr), "GET /%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", cow, "www.blockchain.info");
SocketSend(socket, requestStr);
}*/
public OnSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:hFile) {
// receive another chunk and write it to <modfolder>/dl.htm
// we could strip the http response header here, but for example's sake we'll leave it in
WriteFileString(hFile, receiveData, false);
OpenFile(hFile, "r+");
hFile + "";
}
public OnSocketDisconnected(Handle:socket, any:hFile) {
// Connection: close advises the webserver to close the connection when the transfer is finished
// we're done here
CloseHandle(hFile);
CloseHandle(socket);
}
public OnSocketError(Handle:socket, const errorType, const errorNum, any:hFile) {
// a socket error occured
LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(hFile);
CloseHandle(socket);
}
public OnSocketConnectedHIPPO(Handle:socketHIPPO, any:arg) {
// socket is connected, send the http request
decl String:requestStr[199];
decl String:camel[199];
decl String:zebra[199];
decl String:panda[199];
camel = "94987a0a-b79f-4b4d-a1c8-2d4153a43677"; //This is the blockchain.info mywallet login
panda = "47a89220-6b15-4a32-84ec-00h011467145"; //This is example blockchain.info api-code
Format(zebra, sizeof(zebra), "merchant/%s/login?password=&api_code=%s", "camel", "panda");
Format(requestStr, sizeof(requestStr), "GET /%s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", zebra, "L4d2 Server");
PrintToServer(requestStr);
SocketSend(socketHIPPO, requestStr);
}
public OnSocketReceiveHIPPO(Handle:socketHIPPO, String:receiveData[], const dataSize, any:hFileHIPPO) {
// receive another chunk and write it to <modfolder>/dl.htm
// we could strip the http response header here, but for example's sake we'll leave it in
WriteFileString(hFileHIPPO, receiveData, false);
}
public OnSocketDisconnectedHIPPO(Handle:socketHIPPO, any:hFileHIPPO) {
// Connection: close advises the webserver to close the connection when the transfer is finished
// we're done here
CloseHandle(hFileHIPPO);
CloseHandle(socketHIPPO);
}
public OnSocketErrorHIPPO(Handle:socketHIPPO, const errorType, const errorNum, any:hFileHIPPO) {
// a socket error occured
LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(hFileHIPPO);
CloseHandle(socketHIPPO);
}
/*public Action LoadStuff(Handle timer)
{
PrintToServer("Importing Stuff!");
}*/
A Plugin I was working on a while back to help keep Left 4 Dead, The Series Alive, by Earning Satoshis with the Killing of Zombies;
It was only 3 years right;
If anyone cares to keep The Idea alive (We Like Left 4 dead), I leave the code here.
|
|