Custom Server

Hello everyone,
I’m developing a custom server in c# with a custom library used in the server project and exported to be compatible with unity (c# scripting)

Everything is ok, i have set up the connection, database access and communication between cliend and server is working very well.

But i have some questions that maybe you will answer. (Yeah i know, my english is really bad)
I’m using, for the Lobby, a TCP protocoll ( I know is slow and UDP is better, but i think for lobby things is not too much bad)
The procedure of the game will be this:

  • Login using username and password
    – Server will reply with a success or an error message based on a DB Query (Check credentials)
    – If all is ok, the server will send another packet containing information about the player, Money, Experience, Items etc…

  • Lobby:
    – RoomList , Public Chat, FriendList, and some buttons, one of this go to the Item-Shop

Players can create Rooms, Can select a map, a gamemode, password etc…
When the game start, i will start an UDP connection between players and the server (I want to make this server-based, so no p2p connections)

The game is a 2d game and i have just to syncronize all players and an object that collide with players (Already done this part in “single player”)

  • I’m making a Player class, where there are stored PlayerInformations, like Username, Money, Experience etc. so make a List of class where all connected players informations will be stored, and every X minutes sync all to database.

My questions are :
How i will connect the “sock” of the connected client? I have to add a Sock var to the Player class?
Is good to use TCP protocol for lobby and UDP for game?

Thanks in advance,
Artenio.

#Bump

Answer for Question 1/2: You want multiple sockeds on one Server?

Answer for Question 3: Yes.

First of all thanks you for the reply :slight_smile:
I think multiple sockets are required, one for each player…
I have a player class where i have put a
private Socket cSocket;
private int SessionID = 0;
// And some other vars

the PlayerClass Construction accept 2 arguments
public cPlayer(Socket tSocket, int sID)
{
cSocket = tSocket;
SessionID = sID;
}

When someone connect to the server, i check received data to the database, if all is valid generate a session id, store it in the class, and assign the socket to that player

Ah you want to store the remote socket of the client in a Player Class on the Server yes this is the correct way. It is also helpful to have a Dictionary<ClientSocket, Player> and Dictionary<Player, ClientSocket> so you can get from one to the other without to much searching.

Hmm i think i dont need a dictionary, i have written a Send Method in the Player Class, that use cSocket.Send

At the moment thanks for all,
Really appreciated your help :slight_smile: