correct me if i get something wrong please and thanks oh and once I'm finished mapping everything ill go back and do the bold and also spell check it,but first I'm trying to finish it. I was playing on doing it in the beginning sorry.
-----------Client Side source--------------------ModClientTcp-------This is the most important source of the client by my mind of thought. This is
the part that reads the game ip address and games port to connect it to the
server.
Code:
Sub TcpInit()
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Replaced hard-coded IP with constant.
'****************************************************************
SEP_CHAR = Chr(0)
END_CHAR = Chr(237)
PlayerBuffer = ""
frmMirage.Socket.RemoteHost = GAME_IP
frmMirage.Socket.RemotePort = GAME_PORT
End Sub
it also destroying the connection if its invalid or no connection is detected.
Code:
Sub TcpDestroy()
frmMirage.Socket.Close
If frmChars.Visible Then frmChars.Visible = False
If frmCredits.Visible Then frmCredits.Visible = False
If frmDeleteAccount.Visible Then frmDeleteAccount.Visible = False
If frmLogin.Visible Then frmLogin.Visible = False
If frmNewAccount.Visible Then frmNewAccount.Visible = False
If frmNewChar.Visible Then frmNewChar.Visible = False
End Sub
This folder has a buffer system built in that allows an almost equal buffer
towards all the players.
Code:
Sub IncomingData(ByVal DataLength As Long)
Dim Buffer As String
Dim Packet As String
Dim top As String * 3
Dim Start As Integer
frmMirage.Socket.GetData Buffer, vbString, DataLength
PlayerBuffer = PlayerBuffer & Buffer
Start = InStr(PlayerBuffer, END_CHAR)
Do While Start > 0
Packet = Mid(PlayerBuffer, 1, Start - 1)
PlayerBuffer = Mid(PlayerBuffer, Start + 1, Len(PlayerBuffer))
Start = InStr(PlayerBuffer, END_CHAR)
If Len(Packet) > 0 Then
Call HandleData(Packet)
End If
Loop
End Sub
The mod also sends all the data to the server which then verifies it and send
more data back.
Code:
Sub SendLogin(ByVal Name As String, ByVal Password As String)
Dim Packet As String
Packet = "login" & SEP_CHAR & Trim(Name) & SEP_CHAR &
Trim(Password) & SEP_CHAR & App.Major & SEP_CHAR & App.Minor &
SEP_CHAR & App.Revision & SEP_CHAR & END_CHAR
Call SendData(Packet)
End Sub
----------ModConstants-----------mod constant holds all of the special paths , ip, port, character speeds,
player/npc contants,directions,item,tile,character size, time, admin, and map
constants. some examples.
Code:
' Winsock globals
Public Const GAME_IP = "127.0.0.1"
Public Const GAME_PORT = 7000
' Key constants
Public Const VK_UP = &H26
Public Const VK_DOWN = &H28
Public Const VK_LEFT = &H25
Public Const VK_RIGHT = &H27
Public Const VK_SHIFT = &H10
Public Const VK_RETURN = &HD
Public Const VK_CONTROL = &H11
' Menu states
Public Const MENU_STATE_NEWACCOUNT = 0
Public Const MENU_STATE_DELACCOUNT = 1
Public Const MENU_STATE_LOGIN = 2
Public Const MENU_STATE_GETCHARS = 3
Public Const MENU_STATE_NEWCHAR = 4
Public Const MENU_STATE_ADDCHAR = 5
Public Const MENU_STATE_DELCHAR = 6
Public Const MENU_STATE_USECHAR = 7
Public Const MENU_STATE_INIT = 8
' General constants
Public Const GAME_NAME = "Mirage Source Engine"
Public Const MAX_PLAYERS = 100
Public Const MAX_ITEMS = 200
Public Const MAX_NPCS = 200
Public Const MAX_INV = 50
Public Const MAX_MAP_ITEMS = 20
Public Const MAX_MAP_NPCS = 5
Public Const MAX_SHOPS = 200
Public Const MAX_PLAYER_SPELLS = 20
Public Const MAX_SPELLS = 200
Public Const MAX_TRADES = 10
Public Const NO = 0
Public Const YES = 1
--------ModDatabase---------This is the mod that makes sure the files exist, It makes ,open, or over
writes logs, saves the local maps, and revises the maps as well. example
code.
Code:
Public Sub AddLog(ByVal Text As String)
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Added log constants.
'****************************************************************
Dim FileName As String
Dim f As Long
If Trim(Command) = "-debug" Then
If frmDebug.Visible = False Then
frmDebug.Visible = True
End If
FileName = App.Path & LOG_PATH & LOG_DEBUG
If Not FileExist(LOG_DEBUG, True) Then
f = FreeFile
Open FileName For Output As #f
Close #f
End If
f = FreeFile
Open FileName For Append As #f
Print #f, Time & ": " & Text
Close #f
End If
End Sub
-----------ModDeclares-----------This mod just declares functions which run the game and client with otu
them it probably would not run at all. example code
Code:
' Sound declares
Public Declare Function mciSendString Lib "winmm.dll" Alias
"mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As
String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Declare Function sndPlaySound Lib "winmm.dll" Alias
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As
Long
--------ModDirectX---------This is the first and second most important function to playing any game. it
defines where everything should be placed and where it should stay as what
color it is and stuff. also decides on certain variables like animations 2d and
3d. Sample
Code:
Public Sub InitDirectX()
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Optimized function.
'****************************************************************
' Initialize direct draw
Set DD = DX.DirectDrawCreate("")
frmMirage.Show
With DD
' Indicate windows mode application
Call .SetCooperativeLevel(frmMirage.hWnd, DDSCL_NORMAL)
End With
With DDSD_Primary
' Init type and get the primary surface
.lFlags = DDSD_CAPS
.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set DD_PrimarySurf = DD.CreateSurface(DDSD_Primary)
End With
' Create the clipper
Set DD_Clip = DD.CreateClipper(0)
' Associate the picture hwnd with the clipper
DD_Clip.SetHWnd frmMirage.picScreen.hWnd
' Have the blits to the screen clipped to the picture box
DD_PrimarySurf.SetClipper DD_Clip
' Initialize all surfaces
Call InitSurfaces
End Sub
----------ModGameLogic-------------This mod is an important mod as well it tells the functions of what everything
on the client side does as well as something things from the server side which
the server is also needed as well to communicate and restrict and allow the
client to do what it wants. It controls Main functions as well as status's and
sends them as a string or any variable you want it to send as. sample code
Code:
Public Sub BltFringeTile(ByVal x As Long, ByVal y As Long)
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Optimized function.
'****************************************************************
Dim Fringe As Long
' Only used if ever want to switch to blt rather then bltfast
With rec_pos
.top = y * PIC_Y
.Bottom = .top + PIC_Y
.Left = x * PIC_X
.Right = .Left + PIC_X
End With
Fringe = Map.Tile(x, y).Fringe
If Fringe > 0 Then
With rec
.top = Int(Fringe / 7) * PIC_Y
.Bottom = .top + PIC_Y
.Left = (Fringe - Int(Fringe / 7) * 7) * PIC_X
.Right = .Left + PIC_X
End With
Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_TileSurf, rec,
DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
End If
End Sub
----------ModGlobals------------This mod is used for certain variables. with out this the system would not
know what or how much a certain thing is or how to read it as so it throws
errors at you like my printing machine throws middle fingers. sample code
Code:
' Used to check if in editor or not and variables for use in editor
Public InEditor As Boolean
Public EditorTileX As Long
Public EditorTileY As Long
Public EditorWarpMap As Long
Public EditorWarpX As Long
Public EditorWarpY As Long
' Used for map item editor
Public ItemEditorNum As Long
Public ItemEditorValue As Long
' Used for map key editor
Public KeyEditorNum As Long
Public KeyEditorTake As Long
' Used for map key opene ditor
Public KeyOpenEditorX As Long
Public KeyOpenEditorY As Long
' Map for local use
Public SaveMap As MapRec
Public SaveMapItem(1 To MAX_MAP_ITEMS) As MapItemRec
Public SaveMapNpc(1 To MAX_MAP_NPCS) As MapNpcRec
--------ModHandleData-----------kind of simulate to another thing but its more specific to what it sends. its
calculate the amount of bits to send and what to send them as and such. It
is the packet area for those who cant find the packets when your searching
look here or ill have a monkey bit your arm off.
sample code
Code:
' :::::::::::::::::::::::::::
' :: All characters packet ::
' :::::::::::::::::::::::::::
If LCase(Parse(0)) = "allchars" Then
n = 1
frmChars.Visible = True
frmSendGetData.Visible = False
frmChars.lstChars.Clear
For i = 1 To MAX_CHARS
Name = Parse(n)
Msg = Parse(n + 1)
Level = Val(Parse(n + 2))
If Trim(Name) = "" Then
frmChars.lstChars.AddItem "Free Character Slot"
Else
frmChars.lstChars.AddItem Name & " a level " & Level & " " & Msg
End If
n = n + 3
Next i
frmChars.lstChars.ListIndex = 0
Exit Sub
End If
---------ModSound--------- If you don't know what this is for you deserve a swift kick in the nutz. but it Ok
some people cant hear but see so ill describe it anyways. this is the thing
that plays and sends sound animations in the game. could be used to make
your people magically talk instead of text. sample code.
Code:
Public Sub PlayMidi(Song As String)
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Added music constant.
'****************************************************************
Dim i As Long
i = mciSendString("close all", 0, 0, 0)
i = mciSendString("open " & App.Path & MUSIC_PATH & Song & " type
sequencer alias background", 0, 0, 0)
i = mciSendString("play background notify", 0, 0, frmMirage.hWnd)
End Sub
-----------ModText------------Some people may think this is for special variables at first, but your wrong.
this is the area that defines and transfers text though out the game from
player to player to npc to player.Basically controls fonts color and stuff.
sample code
Code:
Public Sub SetFont(ByVal Font As String, ByVal Size As Byte)
GameFont = CreateFont(Size, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Font)
End Sub
Public Sub DrawText(ByVal hdc As Long, ByVal x, ByVal y, ByVal Text As
String, Color As Long)
Call SelectObject(hdc, GameFont)
Call SetBkMode(hdc, vbTransparent)
Call SetTextColor(hdc, RGB(0, 0, 0))
Call TextOut(hdc, x + 2, y + 2, Text, Len(Text))
Call TextOut(hdc, x + 1, y + 1, Text, Len(Text))
Call SetTextColor(hdc, Color)
Call TextOut(hdc, x, y, Text, Len(Text))
End Sub
------------ModTypes---------------just like modglobal but these are allot less important. these are the variable
settings for the str def or anything you want in your game but they don't run
the game it self.
sample code.
Code:
Type PlayerInvRec
Num As Byte
Value As Long
Dur As Integer
End Type
Type PlayerRec
' General
Name As String * NAME_LENGTH
Class As Byte
Sprite As Integer
Level As Byte
Exp As Long
Access As Byte
PK As Byte
' Vitals
HP As Long
MP As Long
SP As Long
' Stats
STR As Byte
DEF As Byte
SPEED As Byte
MAGI As Byte
POINTS As Byte