K, this is my last one for today. I blame this lame program for not allowing me to NOT put a msg.
This commit is contained in:
u8sand_cp 2010-07-18 20:33:51 -07:00
parent ce94e8d3f8
commit 9debc62ba4
3 changed files with 1 additions and 201 deletions

View file

@ -11,6 +11,7 @@ Documentation
Documentation Documentation
Mud Designer ToolKit.jpeg Mud Designer ToolKit.jpeg
MudDesigner.suo MudDesigner.suo
Networking
UpgradeLog.XML UpgradeLog.XML
_UpgradeReport_Files _UpgradeReport_Files
</Value></Property></Properties></ItemProperties> </Value></Property></Properties></ItemProperties>

View file

@ -1,23 +0,0 @@
_____________ _____________ ___ __
| | | | | / \ |\ | | \
| | | | | / \ | \ | | \
| | | | | / \ | \ | | \
| | |-----------| |___________ /_________\ | \ | | |
| | | | | | | | \ | | |
| | | | | | | | \ | | /
\ / | | | | | | \ | | /
--------- |___________| ____________| | | | \| |__/
Well, this project is in C# but i've heard that we're using the a .dll for
the MUD Engine, and thats what I'll be coding. So I was wondering: I'm
most experienced with C++ and actually would have to go look for it if I
did C#, maybe I could simply code the dll in C++. You see, it doesnt matter
what the dll is coded in, when you link it you can link it to whatever
language. I actually already have a Socket class made in C++ making it even
EASIER for me. So for now I have the C++ Socket header here but I will look
and work on coding it in C#.
- u8sand
-- Status --
- Just found a website and I know where the "winsock control" is.
- Currently learning how to use the winsock control, with UDP

View file

@ -1,178 +0,0 @@
#pragma once
#include <windows.h>
#include <winsock.h>
namespace // unnammed namespace
{
class Socket // socket class, used for all your socket needs.
{
public:
Socket() // constructor, dw about it
{
port = 0;
ip = 0;
type = 0;
sockAddrLen = sizeof(sockAddr);
ready = false;
}
~Socket() // destructor, dw about it
{
port = 0;
ip = 0;
type = 0;
sockAddrLen = 0;
ready = false;
}
int init(int p,unsigned long i,int t) // init, always called first parameter is the socket's port, second
{ // is the ip(if you want to use a String version see FindHostIP() @ the bottom
port = p; // for server's the ip to use is INADDR_ANY last is type, IPPROTO_UDP or IPPROTO_TCP
ip = i; // depending on what type you want UDP is used for any game and is allot more anoying
type = t; // to code while TCP is easy to code but never used for games. D:
if(port <= 0 || (type != IPPROTO_UDP && type != IPPROTO_TCP))
{
ready = false;
return -1;
}
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(port);
sockAddr.sin_addr.S_un.S_addr = i;
ready = true;
return 1;
}
int start() // called after init, will "start" your socket
{
if(!ready)
return 0;
if(type == IPPROTO_UDP)
hSocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
else if(type == IPPROTO_TCP)
hSocket = hSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(hSocket == INVALID_SOCKET)
throw -1;
return 1;
}
int bind() // binding for servers, will bind the socket to the port you specified earlier
{
if(!ready)
return 0;
if(::bind(hSocket,(sockaddr*)(&sockAddr),sizeof(sockAddr)) != 0)
return -1;
return 1;
}
int listen() // listen, only for TCP sockets, sets the server up to receive clients
{
if(!ready)
return 0;
if(::listen(hSocket, SOMAXCONN) != 0)
return -1;
return 1;
}
int connect() // for clients only, will connect to the ip specified earlier
{
if(!ready)
return 0;
if(::connect(hSocket, reinterpret_cast<sockaddr*>(&sockAddr),sizeof(sockAddr)) != 0)
return -1;
return 1;
}
int accept(Socket& sr) // accept will accept a new client connection (only technechly for TCP
{ // but using it w/ UDP will accept the way UDP sockets do.
if(!ready)
return 0;
if(type == IPPROTO_TCP)
sr.hSocket = ::accept(hSocket, (struct sockaddr*)&sr.sockAddr, &sr.sockAddrLen);
else
sr.hSocket = hSocket;
if(sr.hSocket == INVALID_SOCKET)
return -1;
return 1;
}
int send(char* buf,int size) // send a packet of a character array, second parameter specify the
{ // size of the packet(generally 256 or something) (TCP ONLY)
if(!ready)
return 0;
int val = ::send(hSocket, buf, size, 0);
if(val == SOCKET_ERROR)
return -1;
return 1;
}
int recv(char* &buf, int size) // recv a packet of a character array, second parameter specify the
{ // size of the packet(generally 256 or something) (TCP ONLY)
if(!ready)
return 0;
int val = ::recv(hSocket, buf, size, 0);
if(val == SOCKET_ERROR)
return -1;
return 1;
}
int sendto(Socket& sr,char* buf,int size) // first parameter is the socket holding the data of the socket your
{ // sending the data to, second is the packet, third is the size of your packet
if(!ready)
return 0;
int val = ::sendto(sr.hSocket, buf, size, 0, (struct sockaddr *)&sr.sockAddr, sr.sockAddrLen);
if(val == SOCKET_ERROR)
return -1;
return 1;
}
int recvfrom(Socket& sr,char* &buf,int size) // first parameter is the socket holding the data of the socket your
{ // recieving the data from, second is the packet to hold the data, third is
if(!ready) // size of your packet
return 0;
int val = ::recvfrom(sr.hSocket,buf, size, 0, (struct sockaddr *)&sr.sockAddr, &sr.sockAddrLen);
if(val == SOCKET_ERROR)
return -1;
return 1;
}
int end() // closes the socket, call end after your finished using a socket
{
ready = false;
if(::closesocket(hSocket) == SOCKET_ERROR)
return -1;
return 1;
}
bool operator==(const Socket& csr) // == operator, for logic test between two sockets checks if the IPs are the same
{
if(sockAddr.sin_addr.S_un.S_addr == csr.sockAddr.sin_addr.S_un.S_addr)
return true;
return false;
}
SOCKET hSocket;
struct sockaddr_in sockAddr;
int sockAddrLen;
private:
int port;
int type;
unsigned long ip;
bool ready;
};
int initWinsock(WSADATA& wsaData,const int iReqWinsockVer) // call this at the top of your program, initiallizes winsock
{
if(WSAStartup(MAKEWORD(iReqWinsockVer,0),&wsaData) == 0)
{
if(LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
return 1;
else
return -2;
}
else
return -1;
}
int endWinsock() // call this at the end of your program, cleans up winsock
{
return WSACleanup();
}
u_long FindHostIP(const char *pServerName) // accepts a string of your ip and it converts it to unsigned long
{// example FindHostIP("127.0.0.1")
HOSTENT *pHostent;
if (!(pHostent = gethostbyname(pServerName)))
return 0;
else
{
if (pHostent->h_addr_list && pHostent->h_addr_list[0])
return *reinterpret_cast<u_long*>(pHostent->h_addr_list[0]);
}
return 0;
}
}