?
Solved

questions about socket/delphiX

Posted on 2010-03-26
3
Medium Priority
?
464 Views
Last Modified: 2013-11-13
If i have a chatroom and players join and leave which is all fine. However, im going to use delphiX to matchmake (directplay)  and collect ips and launch a game. Does everything ( private msg, all msg, player joins, player leaves ) have to go through directplay or can i just use directx (directplay) just for the matchmaking and not for the chat ?
0
Comment
Question by:966
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
epasquier earned 1000 total points
ID: 28674961
It is definitely best if you use DirectPlay for every message
0
 

Author Comment

by:966
ID: 28679287
Thanks for the comment. Can i ask how is it better? But would it still work if i had my own chat program and then use directplay to collect info's to join game ?

Also can you answer these Questions i have about directy play.

When i use the delphix component and compile it , when i execute it directplay comes up with little boxes i have to tick and stuff. I dont want that to happen.
Is there any examples on how i can use directplay to collect Ip's and launch the game into a multiplayer screen ?

Also..

If i use my chat program as normal, then when the user enters the main chat there will be little chatrooms. When the user enters the chatroom (gameroom) then ill have to use direct play then for messages? or can i still use my chat program, and just only use direct play to actually "launch" the game by collecting Ip's and "nicknames"  in the chatroom.

If you can explain or provide detailed explaintion about delphi directplay for multiplayer matchmaking games, id be greatful.

Just that, if its best to use directplay for every single command " msg, priv msg, on join, on leave " ect.. i should maybe stop my programing of my chat and use direct play fore everything?

If this is the case, provide a working source code i can compile that has a chat client and a server that uses direct play to send and recieve messages with a nicklist to catch nicknames upon join ?

Thanks mate.
0
 

Author Comment

by:966
ID: 28679729
here is something that mauy help you figure out what im after. This is not my code, but i believe its similar and might help someone help me by compiling source.


unit Main; 

interface 

uses 
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
Dialogs, StdCtrls, SyncObjs; 

type 
TMainForm = class(TForm) 
HostButton: TButton; 
ExitButton: TButton; 
PlayerListBox: TListBox; 
procedure ExitButtonClick(Sender: TObject); 
procedure HostButtonClick(Sender: TObject); 
procedure FormCreate(Sender: TObject); 
procedure FormDestroy(Sender: TObject); 
private 
{ Private declarations } 
Critical:TCriticalSection; 
public 
{ Public declarations } 
end; 

var 
MainForm: TMainForm; 

implementation 

{$R *.dfm} 

uses 
DirectPlay8, ActiveX; 

const 
ServerGUID:TGUID='{EDE9493E-6AC8-4f15-8D01-8B163200B966}'; 
ServerPort:DWORD=2507; 
ServerName='Flash-Chat Server'; 

var 
DPServer:IDirectPlay8Server; 
DPAddress:IDirectPlay8Address; 
IsHosting:Boolean; 
AppDesc:DPN_APPLICATION_DESC; 

function DirectPlayMessageHandler(pvUserContext:Pointer;dwMessageId:DWORD;pMsgBuffer:Pointer):HRESULT; stdcall; 
var 
Info:Pointer; 
InfoSize,TempSize:DWord; 
r:hresult; 
begin 
Case dwMessageId of 
DPN_MSGID_CREATE_PLAYER: 
begin 
r:=DPServer.GetClientInfo(PDPNMSG_CREATE_PLAYER(pMsgBuffer)^.dpnidPlayer,nil,@TempSize,0); 
if r=DPNERR_BUFFERTOOSMALL then 
begin 
InfoSize:=TempSize; 
GetMem(Info,InfoSize); 
DPServer.GetClientInfo(PDPNMSG_CREATE_PLAYER(pMsgBuffer).dpnidPlayer,Info,@TempSize,0); 
MainForm.Critical.Enter; 
MainForm.PlayerListBox.AddItem(PDPN_PLAYER_INFO(Info).pwszName,Pointer(PDPNMSG_CREATE_PLAYER(pMsgBuffer).dpnidPlayer)); 
MainForm.Critical.Leave; 
FreeMem(Info,InfoSize); 
end; 
Result:=S_OK; 
end; 
end; 
end; 

procedure TMainForm.ExitButtonClick(Sender: TObject); 
begin 
Close; 
end; 

procedure TMainForm.HostButtonClick(Sender: TObject); 
begin 
if IsHosting then 
begin 
DPServer.Close(0); 
HostButton.Caption:='Host'; 
IsHosting:=False; 
end 
else 
begin 
DPServer.Initialize(nil,DirectPlayMessageHandler,0); 
DPServer.Host(AppDesc,@DPAddress,1,nil,nil,nil,0); 
HostButton.Caption:='Terminate'; 
IsHosting:=True; 
end; 
end; 

procedure TMainForm.FormCreate(Sender: TObject); 
begin 
Critical:=TCriticalSection.Create; 
CoInitializeEx(nil,COINIT_MULTITHREADED); 
FillChar(AppDesc,SizeOf(AppDesc),0); 
AppDesc.dwSize:=SizeOf(DPN_APPLICATION_DESC); 
AppDesc.dwFlags:=DPNSESSION_CLIENT_SERVER or DPNSESSION_NODPNSVR; 
AppDesc.guidApplication:=ServerGUID; 
AppDesc.pwszSessionName:=ServerName; 
IsHosting:=False; 
CoCreateInstance(CLSID_DirectPlay8Server,nil,CLSCTX_INPROC_SERVER,IID_IDirectPlay8Server,DPServer); 
CoCreateInstance(CLSID_DirectPlay8Address,nil,CLSCTX_ALL, IID_IDirectPlay8Address,DPAddress); 
DPAddress.SetSP(CLSID_DP8SP_TCPIP); 
DPAddress.AddComponent(DPNA_KEY_PORT,@ServerPort,SizeOf(ServerPort),DPNA_DATATYPE_DWORD); 
end; 

procedure TMainForm.FormDestroy(Sender: TObject); 
begin 
DPServer.Close(0); 
if DPAddress<>nil then DPAddress:=nil; 
if DPServer<>nil then DPServer:=nil; 
CoUninitialize; 
Critical.Free; 
end; 

end.

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question