Removing iScroll

January 24th, 2012

iScroll is a small JavaScript library that allowed scrolling of elements on mobile Safari. Mobile Safari did not support scrolling of overflow contents before IOS 5 and iScroll made it possible. It works great although it is no longer necessary.

One thing that iScroll and Safari for IOS 5 still do not do is leave the frigging page alone when trying to scroll something that can’t scroll. The problem is that a web page is a scrollable element and the native rubbery feel that is applied to things that scroll makes the web page look like a web page, not a native app. A native app is not scrollable in it’s entirety so webapps look wrong in this regard. iScroll and IOS 5 do nothing to keep the entire page from having that rubbery feel even if the page is set to be 1005 of the screen and no more.

To get rid of the rubbery feel for the whole page and make the webapp seem like a native app, I implemented some quick checks in the code to determine if the target of a scroll action has a certain CSS class, “allowscroll”, and I check to see if the element is already at it’s top or bottom depending on which way the move event is moving. It’s not the best implementation but it works. If the thing that is being scrolled is not one of my scrollable elements or if a scrollable element is already at it’s scroll limit, the default behavior of is prevented. Here’s some code:

            function TouchStartHandler( e )
            {
                lastScreenY = e.touches[0].screenY;
                firstScreenY = lastScreenY;
            }

            function TouchMoveHandler( e )
            {
                var target = e.target;
                while ( target.nodeType != 1 )
                    target = target.parentNode;

                var ScrollContainer = GetParentOfClass( target, "allowscroll" );
                if( ScrollContainer == null )
                {
                    e.preventDefault();
                    return;
                }

                var screenY = e.touches[0].screenY;
                if( screenY > lastScreenY )
                {
                    if( ScrollContainer.scrollTop == 0 )
                        e.preventDefault();
                }
                else if( screenY < lastScreenY )
                {
                    if( ScrollContainer.scrollTop + ScrollContainer.offsetHeight == ScrollContainer.scrollHeight )
                        e.preventDefault();
                }
                else
                    e.preventDefault();

                lastScreenY = e.touches[0].screenY;
            }

This code does a few things to figure out what is going on and it seems to work as expected in my simple webapp. It works for my own div element that holds lists and it works for the textarea element that has scrolling built in. The textarea element is interesting because it acts like the parent of the scrollable content even though there is no visible/accessible child element that is larger and is being scrolled. For my own div that scrolls, I control both the oversized scrolling element as well as the parent container. The code shows this difference.

iBook Internet Sharing to an iPad

January 13th, 2012

I configured the iBook to share its wired network connection through its Airport connection and gave the connection a name and password.

Nothing worked. The iBook didn’t show up on the list of iPad WiFi connections.

I tried to disable the built-in firewall on the iBook and got the error “other firewall software running.” This was wrong and a quick internet search came up with the solution to run “sudo ipfw flush” at a command prompt in a terminal window.

That did the trick and I was able to confirm that the firewall was disabled.

WiFi on the iPad still didn’t work.

Another quick check and it was apparent that the Airport sharing had not happened and I configured it again and made sure that I had clicked on the “start” button to start sharing it.

That did the trick for the Airport configuration and the iPad then showed the iBook in the list of WiFi networks. Entering the password finished the configuration on the iPad and I have now have very good WiFi in my office thanks to Apple having built-in WiFi in the iBook.

An unrelated issue that I discovered at the same time is that if the iPad is connected to iTunes through the USB cable then an app bought using the App Store app will sit on the home screen with a “waiting…” note and will not download. I unplugged the USB cable from the iPad and it immediately started using the WiFi to download the app.

Now I just need to make sure that the Airport WiFi sharing works while the iBook is sitting with the lid closed in what is probably a hibernation state.

Addendum

With the iBook lid closed, the sharing seemed disabled. This is a shortcoming in the iBook design but I can tolerate it since it lets me avoid buying a WiFi router for the office just for my rare and personal iPad use.

iBook internet sharing with iPad

January 13th, 2012

I configured the iBook to share its wired network connection through its Airport connection and gave the connection a name and password.

Nothing worked. The iBook didn’t show up on the list of iPad wifi connections.

I tried to disable the built-in firewall onm the iBook and got the error “other firewall software running.” This was wrong and a quick internet search came up with the solution to run “sudo ipfw flush” at a command prompt in a terminal window.

That did the trick and I was able to confirm that the firewall was disabled.

WiFi on the iPad still didn’t work.

Another quick check and it was apparent that the Airport sharing had not happened and I configured it again and made sure that I had clicked on the “start” button to start sharing it.

That did the trick for the Airport configuration and the iPad then showed the iBook in the list of Wifi networks. Entering the password finished the configuration on the iPad and I have now have very good WiFi in my office thanks to Apple having built-in Wifi in the iBook.

An unrelated issue that I discovered at the same time is that if the iPad is connected to iTunes through the USB cable then an app bought using the App Store app will sit on the home screen with a “waiting…” note and will not download. I unplugged the USB cable from the iPad and it immediately started using the WiFi to download the app.

Now I just need to make sure that the Airport WiFi sharing works while the iBook is sitting with the lid closed in what is probably a hibernation state.

New Programming Projects Page

January 12th, 2012

I just started adding pages to describe each of various programming projects that I have worked on. They are all accessed using an overview page HERE. I will try to keep that page up-to-date as I work on other projects. Check it out to see what I have done.

New AutoResponder Screen Shots

January 11th, 2012

Here are screenshots of the AutoResponder. I still need to change the title and do some other work on it. These were captured from my iPad.

IMG_0075

The main menu screen.

IMG_0076

The teams list for filtering messages per team.

IMG_0077

All messages.

IMG_0078

The registered user filter list.

IMG_0079

The messages screen filtered by user.

IMG_0080

The configuration page.

I intend to use the user list shown earlier for modifying the user list and data but that’s a bit more complex than just editing the text of the XML file that holds all of that data.

IMG_0081

The broadcast email page. A message sent from here goes out to all registered users.

I’ve been getting a bunch of spam at the AutoResponder domain and I will need to start using the registered user list to decide who gets a response. I’d like to send something like a bag of poo to the people who are spamming me.

AutoResponder

January 11th, 2012

I finally have a shorter name for the Automatic Emailer Responder Program. EResponder! I’m not sure why I didn’t come up with it sooner although it’s not all that great.

Crap! Someone already has a product with that name – not unexpected – and they are a spam service as far as I can tell. I think I’ll just use a slightly longer and more generic name like AutoResponder. Wikipedia has an article about that topic but it appears to be generic. It’s not much of an article at all but at least it is not someone’s brand name.

So from now on, this blog will call the Automatic Email Responder Program “AutoResponder”.

AJAX is Easy

January 11th, 2012

The title is not a generality. I mean it in the context of having some JavaScript code to do POST operations and get the results. I also have some PHP code that gets the POST request and creates a response. It too me only a few minutes to add a new page to the auto email web interface and to write the handler for it.
The new web interface home page now looks like the image below and the new broadcast page allows me to send a broadcast message to all registered users without having to use an email program.

image

The auto email program, if you don’t recall, is a program that constantly checks for incoming emails and generates automated responses for them. The main purpose of the web interface shown above is to view the log files for that program in a cool text chat sort of way. Messages can be filtered by team or registered user although the program currently accepts emails and responds to non registered users too. The auto email program itself has the ability to respond to messages as well as forward and broadcast message if the incoming email requests one of those actions. Now I can use the broadcast feature without sending an email to the auto email program. The web interface handles it.

My previous post about the web interface, or webapp is it should be called, is HERE.

My previous post about AJAX is HERE.

I’m going to attempt to create a category for the web app and a category for the auto email program so that posts can be listed by categories more specific than “programming” and “welding”. Hopefully that will be done before anyone ever reads these posts but I won’t comment again on that subject unless it comes up for some reason in some other post.

MFC App to Windows Service

January 10th, 2012

I converted my auto email program to a Windows service. Windows services are interesting because they work well when they are console programs but an MFC based program that has a main window is tricky. Since the auto email program was an MFC application with a main window, I had to change it to compile as a console program and control the email handling thread from the service callback function. Fortunately, Windows programs, those with a window, are called by the OS using the winmain() function but console programs use the main() function. Both can be present and a simple change to the linker settings changes which is called.

Windows services are just regular programs that can be controlled by a callback function within them that the OS calls. Other than that and the required code to let that callback affect the other code, there is no special trick to writing a service. There are issues outside of a program that might become important. For instance, a service runs using a special built-in user account which does not have access to networking features. You cannot open a UNC path on another system using the built-in account. The service can be run using some other user account but it needs to be installed as a service with that account information. Still, none of this is tricky.

One thing I did encounter that is interesting is that a regular user account cannot access the service control manager. I normally write a service program in a way that allows it to run as a non-service console program and to be able to install, start, stop, and remove itself as a service. I found this cool function elsewhere to at least determine if the user account is not elevated, on Vista and Windows 7, to the proper administrator level:

bool IsElevated( void )
{
    bool bResult = false;
    HANDLE hToken    = NULL;

    if ( !::OpenProcessToken(
                ::GetCurrentProcess(),
                TOKEN_QUERY,
                &hToken ) )
    {
        return false;
    }

    TOKEN_ELEVATION te = { 0 };
    DWORD dwReturnLength = 0;

    if ( ::GetTokenInformation(
                hToken,
                TokenElevation,
                &te,
                sizeof( te ),
                &dwReturnLength ) )
    {
        ASSERT( dwReturnLength == sizeof( te ) );

        bResult = te.TokenIsElevated != 0;
    }

    ::CloseHandle( hToken );

    return bResult;
}

This seems to work although I have not tested it on more than my Windows 7 x64 system.

My next task will be to add a message broadcast feature to the web interface for this so that a message can be sent using the iPhone look-alike web interface. That will require more AJAX code and some email sending capability built into the PHP script on the server side. I don’t think I needs a fancy email system, just enough of the SMTP handling code to send a single message that the auto-emailer will act on. An alternative might be to have the auto-emailer check a local file for email-like operations to avoid the initial email send/receive process. The web interface PHP scripts and the auto email service run on the same system and they both knows the location of the auto emailer log files so that is a good option. Another option is to use a socket connection to talk directly to the email handler code although there should never be more than one browser accessing the web interface anyhow. At least not at the same time doing the same thing.

Battlefield 3

January 9th, 2012

I don’t normally blog about computer games other than those that I am designing to want to design. This is an exception because I have some comments about Battlefield 3 and I think it is worth making a note about them.

Battlefield 3 is a first person shooter (FPS) game. There are actually two games in the product like with may other similar game. There is a single player game with a rough story and computer opponents to guide the action and there is a multiplayer online version with no story and human opponents. At least they seem mostly human online.

Single Player

I played through the single player campaign and it was not memorable. Some of the settings and accompanying storylines were interesting to play and some were not. The overall story was acceptable but I felt no connection to it. Some of the settings forced a very linear mode of play where I could not make choices and simply followed a given path while shooting at the expected computer opponents. Some of the action was long and boring with no way to skip it. One particular tank battle was just pointless.

I’ve played these FPS campaigns since Call of Duty 1 and this one was one of the least exciting games.

Multi Player

The multiplayer online game is very different from the single player campaign. There is no beginning or end to the overall action. there is no war, just battles. Sign on, select a server with the appropriate game mode and number of players and wait a few minutes to connect and get started. Then play until that skirmish is over.

I had never played online until a few years ago. I have only played FPS games online so I can’t compare the experience to WoW or other types of games. Once the initial fear of screwing up “in front” of other people went away, I started to really enjoy this type of game. Maybe too much.

I won’t give any more of a summary about multiplayer FPS games in general.

Battlefield 3 offers large maps and a gaming experience that is supposed to be a bit more realistic compared to other FPS games. I think it accomplishes that well. Some things that make this seem a bit realistic, even if they are contrived to make it so, are:

  • The map areas are very large and the terrain and structures look like they could be real places.
  • Nearby bullet strikes and explosions see to make it more difficult to function well. This is hard to measure but seems to happen.
  • Soldiers can’t jump very high and move side-to-side enough to make shooting them impossible like in other games.
  • You cannot run at a guy and knife him if he has fired a shot at you. Unlike other FPS games, you cannot win a gunfight with a knife.
  • There are tanks, jeeps, helicopters, and other vehicles to use.
  • Buildings can collapse.
  • You cannot get up from the prone position quickly enough to run for cover when shot at.

There are still things that happen in this game that make it unrealistic like other FPS games. Part of that is because this is a computer game and not every detail of battle can be simulated and part of it is to keep the gameplay balanced and interesting. Guns that can kill with less bullets often fire slower than guns that cannot. You can’t just pick a better gun and win every match. You also cannot get shot in the leg and go to the hospital. You either recover magically from getting shot or you die. There is nothing in between.

In hard core games, you can shoot and kill your teammates. I like this but there are not many hard core servers out there. I don’t kill my teammates. I like the added difficulty of it. There is also no kill-cam that lets you seem the guy who shot you so you might never go back and find him.

Recon

Unlike Call of Duty games of the past, Battlefield has four classes and each has limitations. You can pick up a weapon of a different class to become that class but you cannot pick up weapons to become a combination of classes. There is no way to have a sniper rifle and a grenade launcher. This keeps things balanced but is not at all realistic.

I have been playing as a sniper to get enough kills to unlock a better gun. I don’t think that there is such a thing in the game but I have not tried enough weapons to know for sure. Documentation is a little sketchy in this regard. A sniper is really a member of the Recon class and has tools to do recognizance activities. You can have motions sensors, remote surveillance drones and mobile spawn beacons for your squad. You also get the sniper rifle which is fun and challenging in this game because bullets drop as they travel as in real life. Long distance kills are very satisfying.

With a high powered scope, the recon soldier can spot enemy soldiers. Now for my first gripe about online games: it seems like in many battles online, most players don’t use the spot feature. Sometimes they do and it helps but sometimes, no one cares to call out enemies. “Spotting” lets you see an enemy, hit a key while pointed at them, and send out a verbal (recorded) message to other players about that enemy. The enemy should then also show up on the mini map for your teammates. I like to spot. The points are not high but I think that it helps win games.

Also, recon players don’t often enough install a SOFLAM device. This is a laser designator and it works automatically as long as targets cross its field of view. It can also be aimed manually using a remote. I’ve found that designated targets are easier to hit with guided weapons and I can also hit a designated helicopter with the Javelin missile even though it cannot target a helicopter on its own.

Assault

The assault solider is really the medic class with an assault rifle. This solider can drop medical kits and can revive fallen comrades. This class is important in tight spaces where there are lots of dead guys and a long run back tot the battle from a spawn location. Once area is taken in the metro tunnel and station, there is no getting it back. Medics are crucial here.

Medics can have a grenade launcher but I have not used that myself.

Support

The support class can hand out ammo which is also important in tight areas like the metro. They also have light machine guns available and can use C4 explosives. I have not used this class much.

Engineer

When I am not recon, I am an engineer. There is a great satisfaction in having a tank blow up on a mine you laid twenty minutes earlier in the game. Mines are one of the perks that do not just go away when you die and you can litter the map with them if you get resupplied by dying. I don’t recall if the ammo box of the support class includes mines but I think not.

This class also has launch weapons like the grenade launcher, Javelin, and Sidewinder. The grenade launcher is less effective but doesn’t need to lock onto a target like the Javelin. The Sidewinder is only good against air targets but I can’t manage to be effective with it. It takes too long to lock on and aircraft usually have flares available again before I can launch a second missile at them.

Vehicles

There is no specific class for vehicles but if the terrain suits it, the engineer class with a repair tool is the best choice when using tanks and IFVs. A helicopter can be landed and repaired but it’s a bit harder to get out of the fight to make the repairs.

My next gripe: Too many people take a vehicle and don’t bother to pick up other soldiers. We can’t all jog to the battlefield but too many people snatch a jeep and drive off with two empty seats. There is a mounted gun that if very effective if there is a second player in that jeep!

I’m getting good with the helicopter. I figured out how to set up my joystick and throttle so that the controls are almost like the MS Flight Simulator flying copters. Unfortunately, the game does not support multiple joysticks so I had to unplug my foot rudder controls and use the twist action of the joystick instead. It’s not as realistic but seems to work well.

Tips

Since the web has lots of basic tips about playing with the right class, joining a squad, and other things, I’ll only give this tip that no one every suggests: don’t bother to take all of the objectives in a game of Conquest. The team only needs 4 of seven to get a benefit and leaving objectives unguarded ends up losing the game for an otherwise winning team. Sure it’s no fun to guard an objective but it’s a good way to win.

Back from Vacation

January 9th, 2012

Although I did no real work of any sort and have no new information to share, I do think a post is in order:

I’m back from two weeks of vacation. It seemed like more than that for some reason.

I plan on working only a little more on the auto email program and web interface. I think I might make it a Windows service so that it is running constantly. I don’t know what to do with it or the interface since I have not decided if there should be a scoring system for right and wrong answers. Keeping track of wrong answers would help keep people fro guessing if the response is a number.

I might revisit the train game code. I still think that a more realistic railroad simulation/game would be great.

I also may be porting someone else’s code to the Windows phone. That might be interesting.

Dave