AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Precache that MOTD (https://forums.alliedmods.net/showthread.php?t=61218)

Vet 09-24-2007 10:58

Precache that MOTD
 
1 Attachment(s)
This is kind of a luxury proceedure for the perfectionist server op with a somewhat involved or lengthy MOTD. What it does is precaches your MOTD to the client's machine and loads it from there. So your MOTD will display instantly. Eliminating that annoying blank screen that's displayed while your MOTD loads from wherever in the world you have it stored. As you may have noticed, I have way too much free time.

This proceedure won't do you a lot of good if...
-Your MOTD is relativly simple, because your load time is probably fairly short anyway.
-Your MOTD includes references to external content because the external content will not be precached.
-Your MOTD changes often, because its somewhat complicated and needs to be redone every time you change your MOTD.
-You don't know what's going on here, because this method requires a lot coordination between files and content.

What you need...
1) A simple motd.txt file stored on the server that directs the MOTD to load from the client's hard drive.
2) All your MOTD content. The main htm file, background, graphics, sounds etc.
3) A fastdownload server that mirrors the content (recommended but not required).
4) A plugin to precache the content.
5) Knowledge. Understand what's going on here or you're in for a headache.

Implementation...
1) The motd.txt file. Here's a sample. Notice the frame src parameter. It begins with ./ to direct the content to the local HD. The full path is where the content is stored on the HD and needs to be unique. Note the folders. The motds folder will be created by the plugin to store all MOTDs in a common place. The sample subfolder alphadogcs01 should be replaced with your unique folder name.
Code:

<frameset cols="*" framespacing="0" frameborder="no" border="0">
<frame name="frame_main" src="./motds/alphadogcs01/index_v1.htm">
</frameset>

2) All your MOTD content needs to be stored on your server in the SAME locations as denoted in the motd.txt file. In this example, it would be \cstrike\motds\alphadogcs01\. Store and refer to all content within the same single folder. DO NOT use subfolders. For this sample, the only content you have is grecloth.jpg, header2.jpg and the main htm file itself, index_v1.htm. If your MOTD changes, be sure to give the main file a new name (like index_v2.htm). Otherwise a client that already has the MOTD precached on his machine will still see the old version.
Code:

<html>
<body background="grecloth.jpg" text="#c1b689">
<center>
<img src="header2.jpg">
<h2>* Welcome to the Server *</h2>
</center>
<h4>Server Rules:<br>
<hr>
blah blah blah
<hr>
Thank You for Visiting Our Server!</h4>
</body>
</html>

3) Copy the content to your fastdownload server, if available, using the same folder structure.

4) Now all we need is a plugin to precache the files to the clients. You can write your own hard coded plugin if your MOTD will never change. But if it does change, you'll need to rewrite it. Here's a hard coded dedicated plugin applicable to the sample...
Code:

#include <amxmodx>
public plugin_precache()
{
 precache_generic("motds/alphadogcs01/index_v1.htm")
 precache_generic("motds/alphadogcs01/grecloth.jpg")
 precache_generic("motds/alphadogcs01/header2.jpg")
}
public plugin_init()
{
 register_plugin("Precache_MOTD", "0.1", "Vet")
}

Or, I've written a plugin (get below) that uses a file motdload.ini stored in the amxmodx/configs/ folder to read the unique folder name and content files. A motdload.ini file for this sample would look like...
Code:

// Your unique folder name
alphadogcs01
 
// MOTD files to precache
index_v1.htm
grecloth.jpg
header2.jpg

Its a lot of work for a small reward. But if you like things 'just so', its nice.

Wilson [29th ID] 09-26-2007 03:33

Re: Precache that MOTD
 
Vet, you're a genious.

purple_pixie 09-27-2007 05:13

Re: Precache that MOTD
 
Seconded.

Sadly my MOTD's tend to be dynamic, but still some dashed good work, what.


All times are GMT -4. The time now is 22:53.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.